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