View Code of Problem 7

#include <iostream>
#include <sstream>
#include <stdio.h>
#include <string>
#include <math.h>
#include <algorithm>
#include <stdlib.h>
#include <stack>
#include <map>
#include <set>
#include <queue>
using namespace std;
map<int,int> mp;

    int main()
    {
        #ifdef  ONLINE_JUDGE
        #else
        freopen("1.txt","r",stdin);
        #endif
        int k;
        cin>>k;
        while(k--)
        {
            mp.clear();
            int n;
            cin>>n;
            while(n--)
            {
                int a,b;
                cin>>a;
                getchar();
                cin>>b;
                if(mp.find(a)==mp.end())
                    mp.insert(make_pair(a,b));
                if(mp.find(b)==mp.end())
                    mp.insert(make_pair(b,a));
            }
            int m;
            cin>>m;
            while(m--)
            {
                int a;
                cin>>a;
                if(mp.find(a)!=mp.end()) cout<<mp[a];
                else cout<<"UNKNOW";
                if(m>0) cout<<endl;
            }
            if(k>0) cout<<endl<<endl;
        }

        return 0;
    }

Double click to view unformatted code.


Back to problem 7