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

猜你喜欢

转载自blog.csdn.net/zhaobaole2018/article/details/84991524
今日推荐