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

全部评论

相关推荐

1.&nbsp;多做一劳永逸的事情。很多事情一次学会基本可以大学四年都不再为这类事情发愁。小的比如学会markdown,记笔记就变得方便快捷;大的比如自己经常要发布上线服务,就花几天搭建一个集群。2.&nbsp;时刻具备3-7天掌握一项技能的心理准备。无论是学科竞赛、期末考试,还是准备实习、秋招,很多时候当你需要快速运用某项技能做事的时候,不会有那么多时间给你准备,这时候就需要速成。3.&nbsp;加入/组建一个技术团体,社团/面试群/社群/技术博主的圈子,并且养成水群习惯。只有你参与并融入你正在追求的事业的氛围里,你才能保持动力去做一件事。推荐一个博主【程序员牛肉】的圈子:https://pd.qq.com/s/daelsgft54.&nbsp;尽早明确自己距离目标还差什么。很多人学习的非常努力,但是方向不明确。最简单的例子,很多我帮忙找实习秋招的朋友,简历都过不了,却花大把时间在背八股上。面试的过程是阶段性的,要考虑的先是有面试机会、再是怎么面试。5.&nbsp;思维不要被约束。后端语言java、c++可以,golang也可以;项目苍穹外卖、黑马点评可以,github上的高star项目也可以;数据库用mysql、redis可以,用postgresql也可以;项目里的ai模块用rag、mcp可以,最简单的function&nbsp;call也可以。帮很多人看简历问题的时候,很多东西都是硬写上去的,项目是自己的,不是非要和网上大流一致才是好项目。
想进开水团喝开水:杭电也是双非是吧
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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