模拟-蚱蜢
蚱蜢只能在元音字母(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);
}
}
本文介绍了一种基于元音字母的跳跃算法,蚱蜢在字符串中只能在特定的元音字母上跳跃,每次跳跃的能力值由两个位置的差决定。通过C++实现,计算了蚱蜢跳跃过程中的最大能力值。
2349

被折叠的 条评论
为什么被折叠?



