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 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.
ABABBBACFEYUKOTT
4
AAA
1
题意:
含有大写字母的字符串,蚂蚱只能够落到元音字母,问经过的最大长度是多少。
思路:
简单的模拟情况,特殊情况就是在结尾处也没有元音字母。。。卡在这里,直接成灰名了。
AC CODE:
#include<stdio.h>
#include<cstring>
#include<algorithm>
#define HardBoy main()
#define ForMyLove return 0;
using namespace std;
const int MYDD = 1103;
bool Judge(char a) {
if(a == 'A'||a == 'E'|| a == 'I'|| a == 'O'|| a == 'U'|| a == 'Y') {
return 1;
}
return 0;
}
int HardBoy {
char s[MYDD];
scanf("%s", s);
int slen = strlen(s);
int ans = -1, Last = -1, j;
for(j = 0; j < slen; j++) {
if(Judge(s[j])) {
ans = max(ans, j-Last);
Last = j;
}
}
ans = max(ans, j-Last);
// if(ans == -1) ans = slen+1;
printf("%d\n", ans);
ForMyLove
}
/*
XXXX
CFHFPTGMOKXVLJJZJDQW
*/
WA code:
#include<stdio.h>
#include<cstring>
#include<algorithm>
#define HardBoy main()
#define ForMyLove return 0;
using namespace std;
const int MYDD = 1103;
bool Judge(char a) {
if(a == 'A'||a == 'E'|| a == 'I'|| a == 'O'|| a == 'U'|| a == 'Y') {
return 1;
}
return 0;
}
int HardBoy {
char s[MYDD];
scanf("%s", s);
int slen = strlen(s);
int ans = -1, Last = -1, j;
for(j = 0; j < slen; j++) {
if(Judge(s[j])) {
ans = max(ans, j-Last);
Last = j;
}
}
if(ans == -1) ans = slen+1;
printf("%d\n", ans);
ForMyLove
}
本文介绍了一个有趣的算法问题:如何计算跳蚤跨越特定字符串所需的最小跳跃能力。通过分析字符串中的元音字母位置,确定跳蚤从起点到终点的最大跳跃长度。
1427

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



