codeforces#378 Div.2 A. Grasshopper And the String
来源:互联网 发布:面试问到java项目上线 编辑:程序博客网 时间:2024/05/22 00:19
题意是给定一个全大写字母组成的字符串(长度不超过100),找出其中连续两个元音之间的最大距离。(连续两个元音是指中间没有其他元音)。
首先,元音有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;}
题目分有元音,没元音,如果是判断条件是是否为元音的话,要注意最后一段也就是最后一个元音到末尾的距离要放入考虑。
0 0
- Codeforces Round #378 (Div. 2)A. Grasshopper And the String
- Codeforces Round #378 (Div. 2) A. Grasshopper And the String
- codeforces#378 Div.2 A. Grasshopper And the String
- Codeforces Round #378 (Div. 2)A.Grasshopper And the String【水题】模拟
- codefroces Codeforces Round #378 (Div. 2) A. Grasshopper And the String
- Codeforces Round #378 (Div. 2) A. Grasshopper And the String(水题求跳跃距离)
- Codeforces 733A Grasshopper And the String
- codeforces--733A. Grasshopper And the String
- CodeForces 733A - Grasshopper And the String
- Codeforces 733A Grasshopper And the String
- A. Grasshopper And the String
- A. Grasshopper And the String
- 【非常高%】【codeforces 733A】Grasshopper And the String
- [codeforces] A. Grasshopper And the String 简单模拟
- 733A Grasshopper And the String codeforces(水题)
- CodeForces 733A Grasshopper And the String(水题)
- CodeForces 733 A.Grasshopper And the String(水~)
- Codeforces Round #382 (Div. 2) A. Ostap and Grasshopper
- Linux多线程的同步与互斥
- 串口的一些高级用法arduino
- java socket多线程聊天室(一)
- 数据定义伪指令
- dedecms最新版本存在远程包含漏洞--可getshell
- codeforces#378 Div.2 A. Grasshopper And the String
- php中操作数据库
- 麻烦11月对我好一点
- Crisis of HDU 还是母函数
- Graphviz
- 51NOD-1674 区间的价值 V2
- Java回顾之JDBC
- Unix下的一些傻瓜问题
- GoogLeNet