NYOJ Grasshopper And the String

来源:互联网 发布:人工智能手机芯片 编辑:程序博客网 时间:2024/06/06 00:00

One day, the Grasshopper was jumping on the lawn and found a piece of paper with a string. Grasshopper became interested what is the minimum jump ability he should have in order to be able to reach the far end of the string, jumping only on vowels of the English alphabet. Jump ability is the maximum possible length of his jump.

Formally, consider that at the begginning the Grasshopper is located directly in front of the leftmost character of the string. His goal is to reach the position right after the rightmost character of the string. In one jump the Grasshopper could jump to the right any distance from 1to the value of his jump ability.

The picture corresponds to the first example.

The following letters are vowels: 'A', 'E', 'I', 'O', 'U' and 'Y'.

Input

The first line contains non-empty string consisting of capital English letters. It is guaranteed that the length of the string does not exceed 100.

Output

Print single integer a — the minimum jump ability of the Grasshopper (in the number of symbols) that is needed to overcome the given string, jumping only on vowels.

Examples
input
ABABBBACFEYUKOTT
output
4
input
AAA
output
1

好吧,虽然这仅仅是一道非常简单的水题,但是在打周赛的是却硬生生地卡了我一个小时之久,一直到比赛结束我都没有A掉这道题。。。
你以为是因为翻译?
那你还是太天真了!
因为我本来做的就是翻译过的题目。
我的题目是这样的:

某日,一只蚂蚱来到了一片字母草地。草地由n个大写字母组成。蚂蚱一开始在草地的最左边(位置0),它要去往草地的最右边(位置n+1)。这只蚂蚱只在元音字母上跳跃(起点和终点除外)。定义这只蚂蚱的跳跃能力为它一次跳跃能跳过的最远距离。

试问,若要让这只蚂蚱顺利到达终点,蚂蚱的跳跃能力最小是多少?下图是样例1的参考图:

元音字母有: 'a', 'E', 'I', 'O', 'U','Y'.

Input

一行一个字符串s,只有大写字母,描述这个草地。长度小于 1000。

Output

输出一个整数,表示这只蚂蚱最小跳跃能力。

Sample Input

ABABBBACFEYUKOTT

AAA

 

Sample Output

 4

1

Hint


你问我都翻译好了为什么还被卡,是太菜了?
虽然我是很菜,但是这道题真的把我坑吐血了;
我只想问:为什么元音字母是 'A', 'E', 'I', 'O', 'U' and 'Y',这个'y'到底为什么会出现在这里!!!!!
我也很绝望啊!!!
好吧,其实只是想提醒你们要认真读题,仅此而已。恩,就是这样。。。

代码如下:
#include<stdio.h>#include<string.h>#include<algorithm>using namespace std;char a[1010];int main(){    memset(a,0,sizeof(a));    while(~scanf("%s",a))    {        int b[1010]={0},c[1010]={0},d=0,k=1;        int len=strlen(a);        for(int i=0; i<len; i++)        {            if(a[i]=='A'||a[i]=='E'||a[i]=='I'||a[i]=='O'||a[i]=='U'||a[i]=='Y')                b[d++]=i;        }        c[0]=b[0]+1;        for(int i=1; i<d; i++)            c[k++]=b[i]-b[i-1];        c[k++]=len-b[d-1];        sort(c,c+k);        if(d!=0)        printf("%d\n",c[k-1]);        if(d==0)            printf("%d\n",len+1);    }    return 0;}


原创粉丝点击