模拟题-蚱蜢

模拟-蚱蜢
蚱蜢只能在元音字母(A、E、I、O、U、Y)间跳跃,一次跳跃所需的能力是两个位置的差。纸带所需的能力值为蚱蜢从纸带开头的前一个位置根据规则跳到纸带结尾的后一个位置的过程中能力的最大值。

#include<bits/stdc++.h>
using namespace std;
int main()
{
    char s[105];
    scanf("%s",s);
    int n=strlen(s);
    int t=0;
    int pos=0;
    int ans=-1;
    int flag=0;
    for(int i=0; i<n; i++)
    {
        if(s[i]=='A'||s[i]=='E'||s[i]=='I'||s[i]=='O'||s[i]=='U'||s[i]=='Y')
        {
            flag=1;
            t=pos;
            pos=i;
            ans=max(pos-t,ans);
        }
    }
    if(flag==0)
    {
        cout<<n+1<<endl;
    }
    else
    {
        printf("%d\n",ans);
    }
}

猜你喜欢

转载自blog.csdn.net/Li_Hongcheng/article/details/83033500