contest: Codeforces Round #300, problem: (A) Cutting Banner(解法 1、2)

注意看题,只能切去一段

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.

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

  

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;
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值