2015年2月6日 星期五

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

#include <iostream>
#include <cstring>
#include <cstdio>
#include <vector>
#include <map>

using namespace std;

int T;
map<string, bool> m;
vector<string> v;

char sound[20000];
char lyrics[20000];

int main()
{
    scanf("%d", &T);

    while( T-- )
    {
        m.clear();
        v.clear();

        scanf(" %[^\n]", sound);

        char *c = strtok(sound, " ");

        while( c )
        {
            v.push_back(string(c) );
            c = strtok(NULL, " ");
        }

        scanf(" %[^\n]", lyrics);

        while( strcmp(lyrics, "what does the fox say?") )
        {
            char *c = strtok(lyrics, " ");
            c = strtok(NULL, " ");
            c = strtok(NULL, " ");
            m[string(c) ] = true;
            scanf(" %[^\n]", lyrics);
        }

        bool flag = false;

        for(int vi = 0; vi < v.size(); vi++)
        {
            if( m.find(v[vi] ) != m.end() ) continue;

            if( flag ) printf(" ");
            flag = true;

            printf("%s", v[vi].c_str());
        }

        puts("");
    }
}

沒有留言:

張貼留言