the reason of failure:1、数据不过,因为有可能一个AEIOUY都没有,直接一步跳过,而我的if中要求max不为0
how to solve:把if(f1>max&&max)改为if(f1>max)
question:
where is difficult:
key point:水题,注意数据!
my thinking:
题目:
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 from1 to the value of his jump ability.
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.
ABABBBACFEYUKOTT
4
AAA
1
#include <iostream>
#include <string.h>
using namespace std;
int main(){
char str1[105];
int max=0,f1=1;
cin >> str1;
int length=strlen(str1);
for(int i=0;i<length;i++){
if(str1[i]=='A'||str1[i]=='E'||str1[i]=='I'||str1[i]=='O'||str1[i]=='U'||str1[i]=='Y'){
if(f1>max) max=f1;
f1=1;
}else{
f1++;
}
}if(f1>max) max=f1;
cout << max;
}