codeforces#378 Div.2 A. Grasshopper And the String
2016-11-01 21:10
302 查看
题意是给定一个全大写字母组成的字符串(长度不超过100),找出其中连续两个元音之间的最大距离。(连续两个元音是指中间没有其他元音)。
首先,元音有6个,不是5个,分别是’A’ ‘E’ ‘I’ ‘O’ ‘U’和 ‘Y’,注意有个 Y !
其次样例里有超过100的字符串,数组要开大点,
一开始开的是105,WA。改成150,WA。改成1500,可以了。
原因我自己也不知道。还有相同的样例自己CB跑是101,跑到cf上就成错误的102了。原因也不知道 。
题目分有元音,没元音,如果是判断条件是是否为元音的话,要注意最后一段也就是最后一个元音到末尾的距离要放入考虑。
首先,元音有6个,不是5个,分别是’A’ ‘E’ ‘I’ ‘O’ ‘U’和 ‘Y’,注意有个 Y !
其次样例里有超过100的字符串,数组要开大点,
一开始开的是105,WA。改成150,WA。改成1500,可以了。
原因我自己也不知道。还有相同的样例自己CB跑是101,跑到cf上就成错误的102了。原因也不知道 。
#include<bits/stdc++.h> using namespace std; const int MAX_N = 1000+50; int main() { char ch[MAX_N]; int d[MAX_N]; memset(d,0,sizeof(d)); d['A']=d['E']=d['I']=d['O']=d['U']=d['Y']=1; ch[0]='0'; for(int i=1;i<=100;i++){ scanf("%c",&ch[i]); if(ch[i]=='\n') { ch[i]='\0'; break; } } int n=strlen(ch)-1,ans=-1; //cout<<n<<endl; for(int i=1;i<=n;i++){ if(d[ch[i]]) { ans=i; break; } } if(ans==-1) { cout<<n+1<<endl; return 0; } int last=ans; for(int i=ans+1;i<=n;i++){ if(d[ch[i]]) { ans=max(ans,i-last); last=i; } } cout<<max(ans,n+1-last)<<endl; }
题目分有元音,没元音,如果是判断条件是是否为元音的话,要注意最后一段也就是最后一个元音到末尾的距离要放入考虑。
相关文章推荐
- Codeforces Round #378 (Div. 2)A. Grasshopper And the String
- Mahmoud and Ehab and the binary string CodeForces - 862D 二分+交互题
- Codeforces Round #430(Div.2)Problem C Ilya And The Tree(DFS)
- Codeforces Round #290(Div.2) B.Fox And Two Dots
- Codeforces Round #267 Div.2 D Fedor and Essay -- 强连通 DFS
- Codeforces Round #297 (Div. 2)B Pasha and String
- Codeforces Round #312 (Div. 2)-B. Amr and The Large Array-暴力
- codeforcesB. Amr and The Large Array
- Dima and Salad -----codeforces # 214 div.2
- Codeforces Round 261 Div.2 D Pashmak and Parmida&#39;s problem --树状数组
- codeforces #312 B B. Amr and The Large Array(统计)
- codeforces B. Pasha and String
- Codeforces Round #250 D - The Child and Sequence/[TYVJ3838] DQS和序列(by 帝江&Darkfalmes)
- codeforces#289_B Polo the Penguin and Matrix
- Codeforces Round #250 (Div. 1) D. The Child and Sequence
- Codeforces Round #195 (Div. 2) A. Vasily the Bear and Triangle
- Codeforces Round #250 (Div. 2)——The Child and Set
- Codeforces Round #250 (Div. 1) A. The Child and Toy
- Codeforces Round #190 DIV.2 A. Ciel and Dancing
- Codeforces Round #250 (Div. 1) D. The Child and Sequence