一道在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之路
一道在CF上WA了9次才AC的A题题目与10个版本的代码代码的更多相关文章
- CF上的3道小题(2)
CF上的3道小题(2) T1:CF630K Indivisibility 题意:给出一个数n,求1到n的数中不能被2到9中任意一个数整除的数. 分析:容斥一下,没了. 代码: #include < ...
- CF上的3道小题(1)
CF上的3道小题 终于调完了啊.... T1:CF702E Analysis of Pathes in Functional Graph 题意:你获得了一个n个点有向图,每个点只有一条出边.第i个点的 ...
- Taurus.MVC-Java 版本打包上传到Maven中央仓库(详细过程):5、Maven版本发布与后续版本更新(大结局)
文章目录: Taurus.MVC-Java 版本打包上传到Maven中央仓库(详细过程):1.JIRA账号注册 Taurus.MVC-Java 版本打包上传到Maven中央仓库(详细过程):2.PGP ...
- cf上分的失落->高兴->更失落
cf昨日做出一个题居然div2打了1800多名直接上分了...我原以为垂直落地但是....我现在1399差一分就能蓝名了啊啊啊啊,以后不一定会有这个水平的啊,给个蓝名体验卡不行吗,多加一分会死啊... ...
- 帮朋友 解决一道 LeetCode QJ上问题
引言 对于刷题,自己是没能力的. 最经一个朋友同事考我一道数组题 . 也许能当面试分享吧. 娱乐娱乐. 事情的开始是这样的. 前言 题目 截图 大概意思 是 在一个 数组中,找出其中两个不重复出现的元 ...
- One day one cf,Keep Wa away from me.
Codeforces Round #379 (Div. 2) A水,算字符个数 B水,贪心优先组成后者 C贪心尺取,以消耗排序change那个,然后贪心另一个 D对角线就是x0+y0 == x1+y1 ...
- 一道在输入上有坑点的LCS
原题连接 http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=114&p ...
- CF上部分树形DP练习题
本次 5 道题均来自Codeforce 关于树形DP的算法讲解:Here 791D. Bear and Tree Jumps 如果小熊每次能跳跃的距离为1,那么问题变为求树上任意两点之间距离之和. 对 ...
- 关于一道面试题【字符串 '1 + (5 - 2) * 3',怎么算出结果为10,'eval'除外】
最近徘徊在找工作和继续留任的纠结之中,在朋友的怂恿下去参加了一次面试,最后一道题目是: 写一个函数,输入一个字符串的运算式,返回计算之后的结果.例如这样的: '1 + (5 - 2) * 3',计算出 ...
随机推荐
- jQuery中的.html()和.text()及.val()区别
https://www.cnblogs.com/zhang-xun/p/6766264.html
- Mysql数据类型简介(大概了解)
知道有整型,浮点型,定点数类型( DECIMAL(M,D)M是数据总长度,是小数位 ),日期类,字符串类,二进制类型(存图片路径,视频路径一般用BLOG就行了喔)……不会再去查 讲一下几个专有名词: ...
- python正则表达式提取中文
import urllib.requestimport reurl='https://songsearch.kugou.com/song_search_v2?callback=jQuery112407 ...
- JAVA字符串转日期或日期转字符串【转】
JAVA字符串转日期或日期转字符串[转] 文章中,用的API是SimpleDateFormat,它是属于java.text.SimpleDateFormat,所以请记得import进 来! 用法: S ...
- Hadoop工作流概念学习系列总述(一)
不多说,这里,直接上干货!从这篇博客起,逐步分享如下: 1.工作流 2.Hadoop工作流(内置) 3.第三方框架--Azkaban(推荐外安装)
- P2955 [USACO09OCT]奇数偶数Even? Odd?
题目描述 Bessie's cruel second grade teacher has assigned a list of N (1 <= N <= 100) positive int ...
- C#实现较为实用的SQLhelper
第一次写博客,想不到写什么好b( ̄▽ ̄)d ,考虑的半天决定从sqlhelper开始,sqlhelper对程序员来说就像helloworld一样,很简单却又很重要,helloworld代表着程序员萌新 ...
- LOJ#121. 「离线可过」动态图连通性(线段树分治)
题意 板子题,题意很清楚吧.. Sol 很显然可以直接上LCT.. 但是这题允许离线,于是就有了一个非常巧妙的离线的做法,好像叫什么线段树分治?? 此题中每条边出现的位置都可以看做是一段区间. 我们用 ...
- Ubuntu 创建docker 容器 系列一
docker 官网安装地址:https://docs.docker.com/install/linux/docker-ce/ubuntu/ 1.Ubuntu的版本要在12.04 LTS 以上,使用un ...
- spring中junit 提示Failed to load ApplicationContext
错误提示: 1:java.lang.IllegalStateException: Failed to load ApplicationContext 2:Error creating bean wit ...