CodeForces 733 A.Grasshopper And the String(水~)

Description
给出一个长度为n的字符串,从0开始跳过这个字符串到n+1位置,除最后一步每步只能跳到元音字母,最小化跳跃距离的最大值
Input
一个长度不超过100的只有大写字母组成的字符串
Output
最小化后的跳跃距离最大值
Sample Input
ABABBBACFEYUKOTT
Sample Output
4
Solution
扫一遍得到相邻两个元音之间最大值,再用0到第一个元音的距离以及最后一个元音到n+1的距离更新下最大值即为答案
Code

#include<cstdio>
#include<iostream>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<vector>
#include<queue>
#include<map>
#include<set>
#include<ctime>
using namespace std;
typedef long long ll;
#define INF 0x3f3f3f3f
#define maxn 111
char s[maxn];
bool check(char c)
{
    if(c=='A'||c=='E'||c=='I'||c=='O'||c=='U'||c=='Y')return 1;
    return 0;
}
int main()
{
    while(~scanf("%s",s+1))
    {
        int n=strlen(s+1);
        int ans=1,pre=0;
        for(int i=1;i<=n;i++)
            if(check(s[i]))
            {
                ans=max(ans,i-pre);
                pre=i;
            }
        ans=max(ans,n+1-pre);
        printf("%d\n",ans);
    }
    return 0;
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值