您的位置:首页 > 其它

2014嘉杰信息杯ACM/ICPC湖南程序设计邀请赛暨第六届湘潭市程序设计竞赛 E

2014-06-07 16:45 477 查看

Welcome to XTCPC

Accepted : 155Submit : 292
Time Limit : 1000 MSMemory Limit : 65536 KB

Problem Description

Welcome to XTCPC! XTCPC start today, you are going to choose a slogan to celebrate it, many people give you some candidate string about the slogan, but the slogan itself must have something relavant to XTCPC, a string is considered relevant to XTCPC if it
become XTCPC after deleting some characters in it. For example, XTCPC, XTCCPCC, OIUXKKJATSADCASPHHC is relevant, XX,FF,GG,CPCXT,XTCP is not. Now you have to write a program to judge whether a string is relevant to XTCPC.

Input

First line an integer t(t≤100), the number of testcases. For each case, there is a string(length≤100, all are uppercase characters).

Output

For each case, output case number first, then "Yes" if the string is relevant, "No" if the string is not relevant. Quote for clarify.

Sample Input

3
XTCPC
CCC
XXXXTTTTCCCCPPPCCC

Sample Output

Case 1: Yes
Case 2: No
Case 3: Yes

水题交错了3遍 这种方法错在了遍历时没按顺序,下为AC代码
#include <iostream>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
using namespace std;

int main()
{
    int n,i;
    int q=1;
    char a[12000];
    scanf("%d",&n);
    getchar();
    while(n--)
    {
       scanf("%s",a);

        int r1=-1,r2=-1,r3=-1,r4=-1,r5=-1;
        int k1=0,k2=0,k3=0,k4=0;
        int len=strlen(a);
        for(i=0;i<len;i++)
        {

            if(a[i]=='X'&&k1==0)
            {
                r1=i;
                k1=1;
            }
           if(a[i]=='T'&&k2==0&&k1)
            {
                r2=i;
                k2=1;
            }
            if(a[i]=='C'&&k3==0&&k1&&k2)
            {
                r3=i;
                k3=1;
            }
               if(a[i]=='P'&&k4==0&&k1&&k2&&k3)
            {
                r4=i;
                k4=1;
            }

        }

        for(i=r4+1;i<len;i++)
        {
            if(a[i]=='C')
            {
                r5=i;
                break;
            }
        }
      
        printf("Case %d: ",q++);
        if(r1!=-1&&r2!=-1&&r3!=-1&&r4!=-1&&r5!=-1)
        {
            if(r1<r2&&r2<r3&&r3<r4&&r4<r5)
               printf("Yes\n");
            else printf("No\n");
        }
        else printf("No\n");

     }

    return 0;
}


这种方法 较上个方法 简单

#include <iostream>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
using namespace std;
char a[10000005];
int main()
{
    int n,i,j;
    char str[]={'X','T','C','P','C'};
    scanf("%d",&n);
    getchar();
    for(j=1;j<=n;j++)
    {
        int k=0;
       scanf("%s",a);
        int len=strlen(a);
        for(i=0;i<len;i++)
        {
            if(a[i]==str[k])
                k++;
        }

        printf("Case %d: ",j);
        if(k==5)
            printf("Yes\n");
        else printf("No\n");

    }

    return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐