Codeforces Round #378 (Div. 2)A题
来源:互联网 发布:php 中str_replace 编辑:程序博客网 时间:2024/06/05 14:58
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’.
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
好吧,题意就是给你一个字符串的序列,让你从头(第一个字母的前一个)开始跳,第一次可以跳任意距离,然后再跳的时候只能跳元音字母A,E,I,O,U,Y(Y?!涨姿势了)
一直跳到最后一个字母的后一个位置,问你跳的最小的最大距离是多少。
#include <cstdio>#include <iostream>#include <cstring>#include <algorithm>using namespace std;char s[100000];bool vis[100000];int len,st;bool flag = 0;int main(){ scanf("%s",s); len = strlen(s+1); st=0; int maxx = 0; if(len == 0&&(s[0] == 'A' || s[0] == 'E'||s[0] == 'I'||s[0] == 'O'||s[0] == 'U'||s[0] == 'Y')) { puts("1"); return 0; } int xx; for(int i = 0; i < len; i ++) { if(s[i] == 'A' || s[i] == 'E'||s[i] == 'I'||s[i] == 'O'||s[i] == 'U'||s[i] == 'Y') { vis[i] = 1; flag = 1; } } if(!flag) { maxx = len+1+1; cout <<maxx <<endl; return 0; } int lenth=0; int x,minn = 2147483645; for(int i = 0; i <= len; i ++) { for(int j = i; j <= len ; j ++) { if(vis[j]) { x = j; break; } } maxx = x+1; maxx = max(maxx,x-i); maxx = max(maxx,i); st = i; for(int j = i; j <= len; j ++) { if(s[j] == 'A' || s[j] == 'E'||s[j] == 'I'||s[j] == 'O'||s[j] == 'U'||s[j] == 'Y') { maxx = max(maxx,j-st); st = j; x = j; } } maxx = max(maxx,len-x+1); minn = min(minn,maxx); } cout <<minn <<endl; return 0;}
- Codeforces Round #378 (Div. 2)A题
- Codeforces Round #378 (Div. 2)(A+B)
- Codeforces Round #181 (Div. 2) A题
- Codeforces Round #184 (Div. 2) A题
- Codeforces Round #172 (Div. 2) A题
- Codeforces Round #166 (Div. 2) A题
- Codeforces Round #132 (Div. 2) A题
- Codeforces Round #131 (Div. 2) A题
- Codeforces Round #133 (Div. 2) A题
- Codeforces Round #137 (Div. 2) A题
- Codeforces Round #138 (Div. 2) A题
- Codeforces Round #147 (Div. 2) A题
- Codeforces Round #141 (Div. 2) A题
- Codeforces Round #143 (Div. 2) A题
- Codeforces Round #135 (Div. 2) A题
- Codeforces Round #163 (Div. 2) A题
- Codeforces Round #146 (Div. 2) A题
- Codeforces Round #111 (Div. 2) A题
- JQuery的入门
- 新Android Studio:创建类时,添加作者名和日期等
- 浅谈unity接入华为SDK流程
- 连续按两次返回键就退出
- iOS指纹识别技术
- Codeforces Round #378 (Div. 2)A题
- ZZULIOJ 1331弟弟的作业
- [caffe]:关于调用caffe库,cmake 编译问题
- 观察者设计模式
- Android添加一个新分区
- 数据库-在表中插入数据;如果存在就更新
- C语言:标记化结构初始化语法
- Angular2-PrimeNG 分页模块源码学习
- 根据推送消息 跳转到指定控制器