@xunuo
2017-01-18T21:27:40.000000Z
字数 1613
阅读 1186
暴力
time limit per test 1 second memory limit per test256 megabytes
来源:codeforces 733 A Grasshopper And the String
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'.
The first line contains non-empty string consisting of capital English letters. It is guaranteed that the length of the string does not exceed 100.
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.
input
ABABBBACFEYUKOTT
output
4
input
AAA
output
1
题意:
只能跳元音:A,E,I,O,U,和Y,输出跳的最多步数,跳过一个为一步
完整代码:
#include<stdio.h>
#include<string.h>
#include<math.h>
#include<algorithm>
using namespace std;
char a[110],b[110],c[110];
int main()
{
while(scanf("%s",a)!=EOF)
{
memset(a,sizeof(a),0);
memset(b,sizeof(b),0);
memset(c,sizeof(c),0);
int l=strlen(a);
int j=0;
for(int i=0;i<l;i++)
{
if(a[i]=='A'||a[i]=='E'||a[i]=='I'||a[i]=='O'||a[i]=='U'||a[i]=='Y')
{
b[j]=i;
j++;
}
}
if(j==0)
{
printf("%d\n",l+1);
}
else
{
int k=1;
c[0]=b[0]+1;
for(int i=1;i<j;i++)
{
c[k]=b[i]-b[i-1];
k++;
}
c[k]=l-b[j-1];
sort(c,c+k+1);
printf("%d\n",c[k]);
}
}
return 0;
}