contest: Codeforces Round #300, problem: (A) Cutting Banner

开始时题意理解错了,以为是随便删,只要能不改变顺序地把剩下的拼起来组成CODEFORCES就行,之后才知道只能切去一段

All that we can manage to do is to cut out somesubstringfrom the banner, i.e. several consecutive letters.

这里的some是某一的意思,因为后面的substring没有加s…….

if the beginning or the end of the original banner was cut out, only one part remains.

i.e. after a substring is cut, several first and last letters are left, it is allowed only to glue the last letters to the right of the first letters.

起初对这两句话很不解….

题意很重要啊TAT

======================================================================================================================================

~~华丽的分割线~~

因为只能切去连续的一段,,所以只可能有三种情况

1.CODEFORCES——

2.—–CODEFORCES

3.CODEFORCES的前半部分—–CODEFORCES的后半部分

method 1:15ms

#include<iostream>#include<cstring>#include<cstdio>#include<string>using namespace std;///char s[100+10];string s,str1,str2;int main(){char des[11]="CODEFORCES";while(cin>>s){int len=s.length();int flag=0;if(len<10) { printf("NO\n");continue; } ///长度不够肯定不行for(int i=0;i<=10;i++) ///这里是10不是len{/// memcpy(str,s,i);str1=s.substr(0,i);/// memcpy(str+i,s+i+len-10,10-i);str2=s.substr(i+len-10,10-i);/// if(!strcmp(str,des))if(str1+str2==des) {flag=1;break;} ///string还可以这样加 哈哈}if(flag) printf("YES\n");else printf("NO\n");}return 0;}

method 2:30ms

#include<iostream>#include<cstring>#include<cstdio>using namespace std;char s[100+10];int main(){char des[11]="CODEFORCES",str[11];///printf("%s\n",des);str[10]='\0';while(~scanf("%s",s)){int len=strlen(s);/// int cnt=0,k=0;int flag=0;if(len<10) { printf("NO\n");continue; }for(int i=0;i<=10;i++){memcpy(str,s,i);memcpy(str+i,s+i+len-10,10-i); ///强大的memcpyif(!strcmp(str,des)) {flag=1;break;}}if(flag) printf("YES\n");else printf("NO\n");}return 0;}那么问题来了,第一个用的string为什么反而快了呢?难道是 substr() 比 memcpy () 快?还是 strcmp() 比较慢?

无神的瞳孔,我迫切想逃离这周遭被钢筋混凝土堆架的城市,

contest: Codeforces Round #300, problem: (A) Cutting Banner

相关文章:

你感兴趣的文章:

标签云: