题目(题目链接:https://codeforces.com/problemset/problem/733/A):  

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

       版本1代码:

 #include <bits/stdc++.h>

 using namespace std;

 int main()
{
char Str[];
int index, ans;
while( ~scanf( "%s", Str ) )
{
index = ans = ;
for( int i = ; Str[i] != '\0'; i ++ )///'A', 'E', 'I', 'O', 'U' and 'Y'.
{
index ++;
if( Str[i] == 'A' || Str[i] == 'E' || Str[i] == 'I' || Str[i] == 'O' || Str[i] == 'U' || Str[i] == 'Y' )
{
ans = index >= ans ? index : ans;
index = ;
}
}
//ans = index >= ans ? index : ans;
printf( "%d\n", ans );
}
return ;
}

版本2代码:

 #include <bits/stdc++.h>

 using namespace std;

 int main()
{
char Str[];
int index, ans;
while( ~scanf( "%s", Str ) )
{
index = ans = ;
if( strlen(Str) == && !( Str[] == 'A' || Str[] == 'E' || Str[] == 'I' || Str[] == 'O' || Str[] == 'U' || Str[] == 'Y' ) )
{
printf( "2\n" );
break;
}
for( int i = ; Str[i] != '\0'; i ++ )///'A', 'E', 'I', 'O', 'U' and 'Y'.
{
index ++;
if( Str[i] == 'A' || Str[i] == 'E' || Str[i] == 'I' || Str[i] == 'O' || Str[i] == 'U' || Str[i] == 'Y' )
{
ans = index >= ans ? index : ans;
index = ;
}
}
ans = index >= ans ? index : ans;
printf( "%d\n", ans );
}
return ;
}

版本3代码:

 #include <bits/stdc++.h>

 using namespace std;

 int main()
{
char Str[];
int index, ans;
bool flag;
while( ~scanf( "%s", Str ) )
{
flag = false;
index = ans = ;
if( strlen(Str) == && !( Str[] == 'A' || Str[] == 'E' || Str[] == 'I' || Str[] == 'O' || Str[] == 'U' || Str[] == 'Y' ) )
{
printf( "2\n" );
break;
}
for( int i = ; Str[i] != '\0'; i ++ )///'A', 'E', 'I', 'O', 'U' and 'Y'.
{
index ++;
if( Str[i] == 'A' || Str[i] == 'E' || Str[i] == 'I' || Str[i] == 'O' || Str[i] == 'U' || Str[i] == 'Y' )
{
ans = index >= ans ? index : ans;
index = ;
flag = true;
}
}
if( strlen(Str) > && !flag )
{
printf( "%d\n", strlen(Str) + );
break;
}
ans = index >= ans ? index : ans;
printf( "%d\n", ans );
}
return ;
}

版本4代码:

 #include <bits/stdc++.h>

 using namespace std;

 int main()
{
char Str[];
int vis[];
int index, ans, last;
while( ~scanf( "%s", Str ) )
{
last = -;
memset( vis, , sizeof(vis) );
index = ;
ans = ;
for( int i = ; Str[i] != '\0'; i ++ )///'A', 'E', 'I', 'O', 'U' and 'Y'.
{
index ++;
if( Str[i] == 'A' || Str[i] == 'E' || Str[i] == 'I' || Str[i] == 'O' || Str[i] == 'U' || Str[i] == 'Y' )
{
vis[index] = i + ;
last = i;
}
}
int tmp = ;
for( int i = ; i < index; i ++ )
{
if(vis[i])
{
///printf( "%d ", vis[i] );
ans = max( vis[i] - tmp, ans );
tmp = vis[i];
}
}
int L = strlen(Str);
ans = max( L - last, ans );
///printf( "last = %d,\tL = %d\n", last, L );
printf( "%d\n", ans );
}
return ;
}

版本5代码:

 #include <bits/stdc++.h>

 using namespace std;

 int main()
{
char Str[];
int vis[];
int index, ans, last;
while( ~scanf( "%s", Str ) )
{
last = -;
memset( vis, , sizeof(vis) );
index = ;
ans = ;
for( int i = ; Str[i] != '\0'; i ++ )///'A', 'E', 'I', 'O', 'U' and 'Y'.
{
index ++;
if( Str[i] == 'A' || Str[i] == 'E' || Str[i] == 'I' || Str[i] == 'O' || Str[i] == 'U' || Str[i] == 'Y' )
{
vis[index] = i + ;
last = i;
}
}
int tmp = ;
for( int i = ; i < index; i ++ )
{
if(vis[i])
{
//printf( "%d ", vis[i] );
ans = max( vis[i] - tmp, ans );
tmp = vis[i];
}
}
int L = strlen(Str);
ans = max( L - last, ans );
//printf( "\nlast = %d,\tL = %d\n", last, L );
printf( "%d\n", ans );
}
return ;
}

版本6代码:

 #include <bits/stdc++.h>

 using namespace std;

 int main()
{
char Str[];
int vis[];
int index, ans, last;
while( ~scanf( "%s", Str ) )
{
last = -;
memset( vis, , sizeof(vis) );
index = ;
ans = ;
for( int i = ; Str[i] != '\0'; i ++ )///'A', 'E', 'I', 'O', 'U' and 'Y'.
{
index ++;
if( Str[i] == 'A' || Str[i] == 'E' || Str[i] == 'I' || Str[i] == 'O' || Str[i] == 'U' || Str[i] == 'Y' )
{
vis[index] = i + ;
last = vis[index];
}
}
int tmp = ;
for( int i = ; i < index; i ++ )
{
if(vis[i])
{
//printf( "%d ", vis[i] );
ans = max( vis[i] - tmp, ans );
tmp = vis[i];
}
}
int L = strlen(Str);
ans = max( L - last, ans );
//printf( "\nlast = %d,\tL = %d\n", last, L );
printf( "%d\n", ans );
}
return ;
}

版本7代码:

 #include <bits/stdc++.h>

 using namespace std;

 int main()
{
char Str[];
int vis[];
int index, ans, last, Tmp;
while( ~scanf( "%s", Str ) )
{
last = -;
memset( vis, , sizeof(vis) );
index = ;
ans = ;
for( int i = ; Str[i] != '\0'; i ++ )///'A', 'E', 'I', 'O', 'U' and 'Y'.
{
index ++;
if( Str[i] == 'A' || Str[i] == 'E' || Str[i] == 'I' || Str[i] == 'O' || Str[i] == 'U' || Str[i] == 'Y' )
{
vis[index] = i + ;
last = i;
} }
int tmp = ;
for( int i = ; i <= index; i ++ )
{
if(vis[i])
{
///printf( "%d ", vis[i] );
ans = max( vis[i] - tmp, ans );
tmp = vis[i];
}
}
int L = strlen(Str);
ans = max( L - last, ans );
///printf( "\nlast = %d,\tL = %d\n", last, L );
printf( "%d\n", ans );
}
return ;
}

版本8代码:

 #include <bits/stdc++.h>

 using namespace std;

 int main()
{
char Str[];
int vis[];
int index, ans, last;
while( ~scanf( "%s", Str ) )
{
last = -;
memset( vis, , sizeof(vis) );
index = ;
ans = ;
for( int i = ; Str[i] != '\0'; i ++ )///'A', 'E', 'I', 'O', 'U' and 'Y'.
{
index ++;
if( Str[i] == 'A' || Str[i] == 'E' || Str[i] == 'I' || Str[i] == 'O' || Str[i] == 'U' || Str[i] == 'Y' )
{
vis[index] = i + ;
last = i;
}
}
int tmp = ;
for( int i = ; i <= index; i ++ )
{
if(vis[i])
{
//printf( "%d ", vis[i] );
ans = max( vis[i] - tmp, ans );
tmp = vis[i];
}
}
int L = strlen(Str);
ans = max( L - last, ans );
ans = max( vis[ index - ] - vis[ index - ], ans );
//printf( "\nlast = %d,\tL = %d,\tindex = %d\n", last, L,index );
printf( "%d\n", ans );
}
return ;
}

版本9代码:

 #include <bits/stdc++.h>

 using namespace std;

 int main()
{
char Str[];
int vis[];
int index, ans, last;
while( ~scanf( "%s", Str ) )
{
last = -;
memset( vis, , sizeof(vis) );
index = ;
ans = ;
for( int i = ; Str[i] != '\0'; i ++ )///'A', 'E', 'I', 'O', 'U' and 'Y'.
{
index ++;
if( Str[i] == 'A' || Str[i] == 'E' || Str[i] == 'I' || Str[i] == 'O' || Str[i] == 'U' || Str[i] == 'Y' )
{
vis[index] = i + ;
last = i;
}
}
int tmp = ;
for( int i = ; i <= index; i ++ )
{
if(vis[i])
{
//printf( "%d ", vis[i] );
ans = max( vis[i] - tmp, ans );
tmp = vis[i];
}
}
int L = strlen(Str);
ans = max( L - last, ans );
if( index >= )
ans = max( vis[ index - ] - vis[ index - ], ans );
//printf( "\nlast = %d,\tL = %d,\tindex = %d\n", last, L,index );
printf( "%d\n", ans );
}
return ;
}

版本10代码:

 #include <bits/stdc++.h>

 using namespace std;

 int main()
{
char Str[];
int vis[];
int index, ans, last, tot;
while( ~scanf( "%s", Str ) )
{
last = -;
memset( vis, , sizeof(vis) );
tot = index = ;
ans = ;
for( int i = ; Str[i] != '\0'; i ++ )///'A', 'E', 'I', 'O', 'U' and 'Y'.
{
tot ++;
if( Str[i] == 'A' || Str[i] == 'E' || Str[i] == 'I' || Str[i] == 'O' || Str[i] == 'U' || Str[i] == 'Y' )
{
vis[ index ++ ] = i + ;
last = i;
}
}
int tmp = ;
for( int i = ; i <= tot; i ++ )
{
if(vis[i])
{
//printf( "%d ", vis[i] );
ans = max( vis[i] - tmp, ans );
tmp = vis[i];
}
}
int L = strlen(Str);
ans = max( L - last, ans );
if( index >= )
ans = max( vis[ index - ] - vis[ index - ], ans );
//printf( "\nlast = %d,\tL = %d,\tindex = %d\n", last, L,index );
printf( "%d\n", ans );
}
return ;
}

其实为了解决这道水题,不止这10个版本的代码,还有中间经过测试后弃用的。归根结底,还是太菜了,能力太差,编程技术烂导致的。

图1 艰难的AC之路

最新文章

  1. poj 2104 K-th Number (划分树入门 或者 主席树入门)
  2. 湖南附中模拟day1 收银员
  3. windows下的socket网络编程(入门级)
  4. 在UIScrollView的delegate方法判断滚动快慢
  5. FTP没权限直接删除目录,写的一个小工具循环删除
  6. [反汇编练习] 160个CrackMe之013
  7. 页面上动态编译及执行java代码
  8. AngularJS Directive 学习笔记
  9. Ubuntu 小白安装血泪史
  10. GC参考手册 —— GC 算法(基础篇)
  11. left join inner join 区别
  12. oracle 约束与索引
  13. Go学习笔记04-函数
  14. Mac Apache Tomcat WebServer 服务器配置
  15. Chrome中安装Firebug插件
  16. JDK8新特性:使用Optional避免null导致的NullPointerException
  17. 记一款bug管理系统(bugdone.cn)的开发过程(2) -如何做好登录界面
  18. android 系统广播
  19. vue--自定义验证指令
  20. [转载]Linux I/O 调度方法

热门文章

  1. UvaLive3942(Trie + dp)
  2. python_面向对象进阶(7)
  3. hadoop-0.20.2伪分布式安装简记
  4. java中stringBuilder的用法
  5. 微信环境支付宝服务窗环境app手机浏览器pc端混合判断
  6. Java&amp;Xml教程(十)XML作为属性文件使用
  7. Makefile介绍
  8. [整理]ADB命令行学习笔记
  9. UGUI世界坐标转换为UI本地坐标
  10. TensorFlow低阶API(四)—— 图和会话