1361.Grasshopper And the String SDNUOJ1361(2018新生第一次周赛测试题)

当时我不会

Description
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 1 to 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
Standard input will contain multiple test cases. The per 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.
Sample Input
ABABBBACFEYUKOTT
Sample Output
4

#include <cstdio>
#include <iostream>
#include <algorithm>
#include <cmath>
#include <cstring>
using namespace std;

int main()
{
    char s[105];
    while(gets(s))
    {
        int len = strlen(s);
        int minn = 0;
        int pre = -1;
        int wid = 0;
        int last = 0;
        bool flag = 0;
        for(int i = 0; i < len; ++i)
        {
            switch(s[i])
            {
            case 'A':
            case 'E':
            case 'I':
            case 'O':
            case 'U':
            case 'Y':
                wid = i - pre;
                pre = i;
                last = i;
                if(wid > minn)
                    minn = wid;
                flag = 1;
                break;
            default:
                break;
            }
        }
//        cout << len - last << '\n';
        if(len - last > minn)
            minn = len - last;
        if(flag)
            cout << minn << '\n';
        else
        {
            cout << len + 1 << '\n';
        }
    }
    return 0;
}

全部评论

相关推荐

不愿透露姓名的神秘牛友
昨天 17:10
点赞 评论 收藏
分享
06-10 21:15
门头沟学院 Java
宁阿:好多这种没🧠的公司,他们估计都不知道毕业的人不能给安排实习岗
实习吐槽大会
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务