一道在CF上WA了9次才AC的A题题目与10个版本的代码代码

       题目(题目链接: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 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代码:

 

 1 #include <bits/stdc++.h>
 2 
 3 using namespace std;
 4 
 5 int main()
 6 {
 7     char Str[111];
 8     int index, ans;
 9     while( ~scanf( "%s", Str ) )
10     {
11         index = ans = 0;
12         for( int i = 0; Str[i] != '\0'; i ++ )///'A', 'E', 'I', 'O', 'U' and 'Y'.
13         {
14             index ++;
15             if( Str[i] == 'A' || Str[i] == 'E' || Str[i] == 'I' || Str[i] == 'O' || Str[i] == 'U' || Str[i] == 'Y' )
16             {
17                 ans = index >= ans ? index : ans;
18                 index = 0;
19             }
20         }
21         //ans = index >= ans ? index : ans;
22         printf( "%d\n", ans );
23     }
24     return 0;
25 }
View Code

 

 

 

       版本2代码:

 

 1 #include <bits/stdc++.h>
 2 
 3 using namespace std;
 4 
 5 int main()
 6 {
 7     char Str[111];
 8     int index, ans;
 9     while( ~scanf( "%s", Str ) )
10     {
11         index = ans = 0;
12         if( strlen(Str) == 1 && !( Str[0] == 'A' || Str[0] == 'E' || Str[0] == 'I' || Str[0] == 'O' || Str[0] == 'U' || Str[0] == 'Y' ) )
13         {
14             printf( "2\n" );
15             break;
16         }
17         for( int i = 0; Str[i] != '\0'; i ++ )///'A', 'E', 'I', 'O', 'U' and 'Y'.
18         {
19             index ++;
20             if( Str[i] == 'A' || Str[i] == 'E' || Str[i] == 'I' || Str[i] == 'O' || Str[i] == 'U' || Str[i] == 'Y' )
21             {
22                 ans = index >= ans ? index : ans;
23                 index = 0;
24             }
25         }
26         ans = index >= ans ? index : ans;
27         printf( "%d\n", ans );
28     }
29     return 0;
30 }
View Code

 

 

 

       版本3代码:

 

 1 #include <bits/stdc++.h>
 2 
 3 using namespace std;
 4 
 5 int main()
 6 {
 7     char Str[111];
 8     int index, ans;
 9     bool flag;
10     while( ~scanf( "%s", Str ) )
11     {
12         flag = false;
13         index = ans = 0;
14         if( strlen(Str) == 1 && !( Str[0] == 'A' || Str[0] == 'E' || Str[0] == 'I' || Str[0] == 'O' || Str[0] == 'U' || Str[0] == 'Y' ) )
15         {
16             printf( "2\n" );
17             break;
18         }
19         for( int i = 0; Str[i] != '\0'; i ++ )///'A', 'E', 'I', 'O', 'U' and 'Y'.
20         {
21             index ++;
22             if( Str[i] == 'A' || Str[i] == 'E' || Str[i] == 'I' || Str[i] == 'O' || Str[i] == 'U' || Str[i] == 'Y' )
23             {
24                 ans = index >= ans ? index : ans;
25                 index = 0;
26                 flag = true;
27             }
28         }
29         if( strlen(Str) > 1 && !flag )
30         {
31             printf( "%d\n", strlen(Str) + 1 );
32             break;
33         }
34         ans = index >= ans ? index : ans;
35         printf( "%d\n", ans );
36     }
37     return 0;
38 }
View Code

 

 

 

       版本4代码:

 

 1 #include <bits/stdc++.h>
 2 
 3 using namespace std;
 4 
 5 int main()
 6 {
 7     char Str[111];
 8     int vis[111];
 9     int index, ans, last;
10     while( ~scanf( "%s", Str ) )
11     {
12         last = -1;
13         memset( vis, 0, sizeof(vis) );
14         index = 0;
15         ans = 1;
16         for( int i = 0; Str[i] != '\0'; i ++ )///'A', 'E', 'I', 'O', 'U' and 'Y'.
17         {
18             index ++;
19             if( Str[i] == 'A' || Str[i] == 'E' || Str[i] == 'I' || Str[i] == 'O' || Str[i] == 'U' || Str[i] == 'Y' )
20             {
21                 vis[index] = i + 1;
22                 last = i;
23             }
24         }
25         int tmp = 1;
26         for( int i = 0; i < index; i ++ )
27         {
28             if(vis[i])
29             {
30                 ///printf( "%d ", vis[i] );
31                ans = max( vis[i] - tmp, ans );
32                tmp = vis[i];
33             }
34         }
35         int L = strlen(Str);
36         ans = max( L - last, ans );
37         ///printf( "last = %d,\tL = %d\n", last, L );
38         printf( "%d\n", ans );
39     }
40     return 0;
41 }
View Code

 

 

 

       版本5代码:

 

 1 #include <bits/stdc++.h>
 2 
 3 using namespace std;
 4 
 5 int main()
 6 {
 7     char Str[111];
 8     int vis[111];
 9     int index, ans, last;
10     while( ~scanf( "%s", Str ) )
11     {
12         last = -1;
13         memset( vis, 0, sizeof(vis) );
14         index = 0;
15         ans = 1;
16         for( int i = 0; Str[i] != '\0'; i ++ )///'A', 'E', 'I', 'O', 'U' and 'Y'.
17         {
18             index ++;
19             if( Str[i] == 'A' || Str[i] == 'E' || Str[i] == 'I' || Str[i] == 'O' || Str[i] == 'U' || Str[i] == 'Y' )
20             {
21                 vis[index] = i + 1;
22                 last = i;
23             }
24         }
25         int tmp = 0;
26         for( int i = 0; i < index; i ++ )
27         {
28             if(vis[i])
29             {
30                 //printf( "%d ", vis[i] );
31                 ans = max( vis[i] - tmp, ans );
32                 tmp = vis[i];
33             }
34         }
35         int L = strlen(Str);
36         ans = max( L - last, ans );
37         //printf( "\nlast = %d,\tL = %d\n", last, L );
38         printf( "%d\n", ans );
39     }
40     return 0;
41 }
View Code

 

 

 

       版本6代码:

 

 1 #include <bits/stdc++.h>
 2 
 3 using namespace std;
 4 
 5 int main()
 6 {
 7     char Str[111];
 8     int vis[111];
 9     int index, ans, last;
10     while( ~scanf( "%s", Str ) )
11     {
12         last = -1;
13         memset( vis, 0, sizeof(vis) );
14         index = 0;
15         ans = 1;
16         for( int i = 0; Str[i] != '\0'; i ++ )///'A', 'E', 'I', 'O', 'U' and 'Y'.
17         {
18             index ++;
19             if( Str[i] == 'A' || Str[i] == 'E' || Str[i] == 'I' || Str[i] == 'O' || Str[i] == 'U' || Str[i] == 'Y' )
20             {
21                 vis[index] = i + 1;
22                 last = vis[index];
23             }
24         }
25         int tmp = 0;
26         for( int i = 0; i < index; i ++ )
27         {
28             if(vis[i])
29             {
30                 //printf( "%d ", vis[i] );
31                 ans = max( vis[i] - tmp, ans );
32                 tmp = vis[i];
33             }
34         }
35         int L = strlen(Str);
36         ans = max( L - last, ans );
37         //printf( "\nlast = %d,\tL = %d\n", last, L );
38         printf( "%d\n", ans );
39     }
40     return 0;
41 }
View Code

 

 

 

       版本7代码:

 

 1 #include <bits/stdc++.h>
 2 
 3 using namespace std;
 4 
 5 int main()
 6 {
 7     char Str[111];
 8     int vis[111];
 9     int index, ans, last, Tmp;
10     while( ~scanf( "%s", Str ) )
11     {
12         last = -1;
13         memset( vis, 0, sizeof(vis) );
14         index = 0;
15         ans = 1;
16         for( int i = 0; Str[i] != '\0'; i ++ )///'A', 'E', 'I', 'O', 'U' and 'Y'.
17         {
18             index ++;
19             if( Str[i] == 'A' || Str[i] == 'E' || Str[i] == 'I' || Str[i] == 'O' || Str[i] == 'U' || Str[i] == 'Y' )
20             {
21                 vis[index] = i + 1;
22                 last = i;
23             }
24 
25         }
26         int tmp = 1;
27         for( int i = 0; i <= index; i ++ )
28         {
29             if(vis[i])
30             {
31                 ///printf( "%d ", vis[i] );
32                 ans = max( vis[i] - tmp, ans );
33                 tmp = vis[i];
34             }
35         }
36         int L = strlen(Str);
37         ans = max( L - last, ans );
38         ///printf( "\nlast = %d,\tL = %d\n", last, L );
39         printf( "%d\n", ans );
40     }
41     return 0;
42 }
View Code

 

 

 

       版本8代码:

 

 1 #include <bits/stdc++.h>
 2 
 3 using namespace std;
 4 
 5 int main()
 6 {
 7     char Str[111];
 8     int vis[111];
 9     int index, ans, last;
10     while( ~scanf( "%s", Str ) )
11     {
12         last = -1;
13         memset( vis, 0, sizeof(vis) );
14         index = 0;
15         ans = 1;
16         for( int i = 0; Str[i] != '\0'; i ++ )///'A', 'E', 'I', 'O', 'U' and 'Y'.
17         {
18             index ++;
19             if( Str[i] == 'A' || Str[i] == 'E' || Str[i] == 'I' || Str[i] == 'O' || Str[i] == 'U' || Str[i] == 'Y' )
20             {
21                 vis[index] = i + 1;
22                 last = i;
23             }
24         }
25         int tmp = 0;
26         for( int i = 0; i <= index; i ++ )
27         {
28             if(vis[i])
29             {
30                 //printf( "%d ", vis[i] );
31                 ans = max( vis[i] - tmp, ans );
32                 tmp = vis[i];
33             }
34         }
35         int L = strlen(Str);
36         ans = max( L - last, ans );
37         ans = max( vis[ index - 1 ] - vis[ index - 2 ], ans );
38         //printf( "\nlast = %d,\tL = %d,\tindex = %d\n", last, L,index );
39         printf( "%d\n", ans );
40     }
41     return 0;
42 }
View Code

 

 

 

       版本9代码:

 

 1 #include <bits/stdc++.h>
 2 
 3 using namespace std;
 4 
 5 int main()
 6 {
 7     char Str[111];
 8     int vis[111];
 9     int index, ans, last;
10     while( ~scanf( "%s", Str ) )
11     {
12         last = -1;
13         memset( vis, 0, sizeof(vis) );
14         index = 0;
15         ans = 1;
16         for( int i = 0; Str[i] != '\0'; i ++ )///'A', 'E', 'I', 'O', 'U' and 'Y'.
17         {
18             index ++;
19             if( Str[i] == 'A' || Str[i] == 'E' || Str[i] == 'I' || Str[i] == 'O' || Str[i] == 'U' || Str[i] == 'Y' )
20             {
21                 vis[index] = i + 1;
22                 last = i;
23             }
24         }
25         int tmp = 0;
26         for( int i = 0; i <= index; i ++ )
27         {
28             if(vis[i])
29             {
30                 //printf( "%d ", vis[i] );
31                 ans = max( vis[i] - tmp, ans );
32                 tmp = vis[i];
33             }
34         }
35         int L = strlen(Str);
36         ans = max( L - last, ans );
37         if( index >= 2 )
38             ans = max( vis[ index - 1 ] - vis[ index - 2 ], ans );
39         //printf( "\nlast = %d,\tL = %d,\tindex = %d\n", last, L,index );
40         printf( "%d\n", ans );
41     }
42     return 0;
43 }
View Code

 

 

 

       版本10代码:

 

 1 #include <bits/stdc++.h>
 2 
 3 using namespace std;
 4 
 5 int main()
 6 {
 7     char Str[111];
 8     int vis[111];
 9     int index, ans, last, tot;
10     while( ~scanf( "%s", Str ) )
11     {
12         last = -1;
13         memset( vis, 0, sizeof(vis) );
14         tot = index = 0;
15         ans = 1;
16         for( int i = 0; Str[i] != '\0'; i ++ )///'A', 'E', 'I', 'O', 'U' and 'Y'.
17         {
18             tot ++;
19             if( Str[i] == 'A' || Str[i] == 'E' || Str[i] == 'I' || Str[i] == 'O' || Str[i] == 'U' || Str[i] == 'Y' )
20             {
21                 vis[ index ++ ] = i + 1;
22                 last = i;
23             }
24         }
25         int tmp = 0;
26         for( int i = 0; i <= tot; i ++ )
27         {
28             if(vis[i])
29             {
30                 //printf( "%d ", vis[i] );
31                 ans = max( vis[i] - tmp, ans );
32                 tmp = vis[i];
33             }
34         }
35         int L = strlen(Str);
36         ans = max( L - last, ans );
37         if( index >= 2 )
38             ans = max( vis[ index - 1 ] - vis[ index - 2 ], ans );
39         //printf( "\nlast = %d,\tL = %d,\tindex = %d\n", last, L,index );
40         printf( "%d\n", ans );
41     }
42     return 0;
43 }
View Code

 

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

图1 喵啊图1 艰难的AC之路

 

posted on 2018-09-24 16:50  25th_engineer  阅读(309)  评论(0编辑  收藏  举报