【codeforces】Grasshopper And the String(div2A)

本文介绍了一道算法题目,蚱蜢需要找到最小跳跃能力以便仅通过元音字母到达字符串末尾。文章提供了完整的代码实现,并解释了如何计算蚱蜢所需的最小跳跃长度。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

A. Grasshopper And the String
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

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'.

Input

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.

Output

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.

Examples
input
ABABBBACFEYUKOTT
output
4
input
AAA
output
1

题意:求只能在元音字母间跳跃的能够实现从串首到串尾的最小长度,就是两个相邻元音字母间的最大距离。

#include<cstdio>
#include<iostream>
#include<cstring>
#include<cmath>
#include<algorithm>
using namespace std;
const int N = 105;
char c[N];
int main() {
	scanf("%s",c);
	int flag=0;
	int ans=-1;
	int l=strlen(c);
	for(int i=0; i<=l; i++) {
		flag++;
		ans=max(ans,flag);
		if(c[i]=='\0'||c[i]=='A'||c[i]=='E'||c[i]=='O'||c[i]=='U'||c[i]=='I'||c[i]=='Y') {
			flag=0;
		}
	}
	printf("%d\n",ans);
	return 0;
}




评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值