2013-2014 ACM ICPC Central European Regional Contest (CERC 13) B题What does the fox say?

题目链接

http://codeforces.com/gym/100299/attachments/download/2035/20132014-acm-icpc-central-european-regional-contest-cerc-13-en.pdf

字符串处理,之前都是用的很麻烦的方式处理这次用的strtok,处理那些用逗号或者空格分开的多个字符串十分方便,要注意用法

#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;
int main()
{
    //freopen("input.in","r",stdin);
    int T;
    char a[1000][1000],st[10010];
    scanf("%d\n",&T);
    for (int Ti=1;Ti<=T;Ti++)
    {
        gets(st);
        char at[1000],b[1000],c[1000];
        scanf("%s %s %s\n",at,b,c);
        int num=1;
        while (strcmp("goes",b)==0)
        {
            strcpy(a[num],c);
            num++;
            scanf("%s %s %s\n",at,b,c);
        }
        char *p,*ans;
        p=strtok(st," ");
        while (p)
        {
            int flag=1;
            for (int i=1;i<=num;i++)
            {
                if (strcmp(a[i],p)==0) flag=0;
            }
            if (flag==1) printf("%s ",p);
            p=strtok(NULL," ");
        }
        printf("\n");
        char aa[100],bb[100];
        scanf("%s %s\n",aa,bb);
    }
    return 0;
}


你可能感兴趣的:(字符串)