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

來源:互聯網
上載者:User

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

開始時題意理解錯了,以為是隨便刪,只要能不改變順序地把剩下的拼起來組成CODEFORCES就行,之後才知道只能切去一段

All that we can manage to do is to cut out some substring from 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);   ///強大的memcpy            if(!strcmp(str,des))  {flag=1;break;}        }        if(flag) printf("YES\n");        else printf("NO\n");    }         return 0;}

那麼問題來了,第一個用的string為什麼反而快了呢?難道是 substr()  比 memcpy ()  快?還是 strcmp() 比較慢?



聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.