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;
}

全部评论

相关推荐

10-10 01:10
已编辑
深圳大学 测试开发
面了100年面试不知...:六月到九月,四个项目一个实习,是魔丸吗
投了多少份简历才上岸
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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