Codeforces Round #208 (Div. 2) Dima and Text Messages
来源:互联网 发布:阿里云是阿里巴巴的吗 编辑:程序博客网 时间:2024/05/16 11:53
题意:输入n,然后输入n个字符串最后在输入一个长串,这n个字符串每个都是开头和结尾加上'<3'问能否在这个长串中找到满足n个字符串前后都加上'<3'所组成的串,如果能则输出yes否则输出no.
思路:输入每输入一个串就给这个串加上<3然后就得到了组成的串,然后在长串中遍历能否找到组成的串。(另外,用库函数strlen会超时,毕竟需要调用10e5次,所以得改进,得自己写strlen,看下面,还有每个字符最后都是'\0',正好用上了)
改进库函数超时代码如下:
#include <bits/stdc++.h>using namespace std;typedef long long LL;#define INF 0x3f3f3f3fchar str[1000005];char str1[1000005];char str2[1000005];int main(){ int n; scanf("%d",&n); str[0]='<';str[1]='3'; int len=2; for(int i=0;i<n;i++) { scanf("%s",str1); //strcpy(str+len,str1); for(int j=0;str1[j];j++) { str[len++]=str1[j]; } str[len]='<'; str[len+1]='3'; len+=2; } scanf("%s",str2); int sum=0; int len2=strlen(str2); for(int i=0;i<len2;i++) { if(str2[i]==str[sum]) sum++; if(sum==len) { break; } } if(sum==len) printf("yes\n"); else printf("no\n");}用c++和string更加简单
代码如下:
#include<bits/stdc++.h>using namespace std;typedef long long LL;#define INF 0x3f3f3f3fstring str1,str,str3;int main(){ int n; scanf("%d",&n); string str2="<3"; str+=str2; for(int i=0;i<n;i++) { cin>>str1; str+=(str1+str2); } cin>>str3; int sum=0; int len3=str3.length(); int len=str.length(); //printf("%d\n",len); //cout<<str<<endl; //cout<<str[0]<<endl; for(int i=0;i<len3;i++) { if(str3[i]==str[sum]) sum++; } if(sum==len) printf("yes\n"); else printf("no\n");}
0 0
- Codeforces Round #208 (Div. 2) B. Dima and Text Messages
- Codeforces Round #208 (Div. 2) B Dima and Text Messages
- Codeforces Round #208 (Div. 2) B. Dima and Text Messages
- Codeforces Round #208 (Div. 2) Dima and Text Messages
- Codeforces Round #208 (Div. 2) A_ Dima and Continuous Line
- Codeforces Round #208 (Div. 2) D. Dima and Hares
- Codeforces Round #208 (Div. 2) A. Dima and Continuous Line
- Codeforces Round #208 (Div. 2) C. Dima and Containers
- Codeforces Round #208 (Div. 2)D. Dima and Hares
- Codeforces Round #208 (Div. 2)E. Dima and Kicks
- Codeforces 358B - Dima and Text Messages 字符串
- Codeforces —— 358B Dima and Text Messages
- B. Dima and Text Messages
- Codeforces Round #167 (Div. 2) 272E Dima and Horses
- Codeforces Round #214 (Div. 2) C. Dima and Salad
- Codeforces Round #214 (Div. 2) C. Dima and Salad
- Codeforces Round #229 (Div. 2) B. Inna, Dima and Song
- Codeforces Round #229 (Div. 2) B. Inna, Dima and Song
- eCryptfs v0.1 Design Document
- JavaScript 原型中的哲学思想
- Socket 学习笔记——InetAdress 最简单的体验
- html编写随笔(一)
- Linux权限管理命令
- Codeforces Round #208 (Div. 2) Dima and Text Messages
- (11)HTML标签详解之<script> <noscript>
- java学习笔记4——I/O流
- BZOJ 1046: [HAOI2007]上升序列
- Spring AMQP + RabbitMQ 3.3.5 ACCESS_REFUSED - Login was refused using authentication mechanism PLAIN
- Codeforces Round #364 (Div. 2)
- Android Intent-filter匹配
- HDU 4462 Scaring the Birds (枚举+暴搜)
- 删除TFS2015SP1的集合特性