CodeForces 733 A.Grasshopper And the String(水~)

来源:互联网 发布:kali linux切换到root 编辑:程序博客网 时间:2024/05/22 01:50

Description
给出一个长度为n的字符串,从0开始跳过这个字符串到n+1位置,除最后一步每步只能跳到元音字母,最小化跳跃距离的最大值
Input
一个长度不超过100的只有大写字母组成的字符串
Output
最小化后的跳跃距离最大值
Sample Input
ABABBBACFEYUKOTT
Sample Output
4
Solution
扫一遍得到相邻两个元音之间最大值,再用0到第一个元音的距离以及最后一个元音到n+1的距离更新下最大值即为答案
Code

#include<cstdio>#include<iostream>#include<cstring>#include<algorithm>#include<cmath>#include<vector>#include<queue>#include<map>#include<set>#include<ctime>using namespace std;typedef long long ll;#define INF 0x3f3f3f3f#define maxn 111char s[maxn];bool check(char c){    if(c=='A'||c=='E'||c=='I'||c=='O'||c=='U'||c=='Y')return 1;    return 0;}int main(){    while(~scanf("%s",s+1))    {        int n=strlen(s+1);        int ans=1,pre=0;        for(int i=1;i<=n;i++)            if(check(s[i]))            {                ans=max(ans,i-pre);                pre=i;            }        ans=max(ans,n+1-pre);        printf("%d\n",ans);    }    return 0;}
0 0