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;
const int maxv=1000010;
int father[maxv];

int main()
{
    #ifdef  ONLINE_JUDGE
    #else
    freopen("1.txt","r",stdin);
    #endif
    int k;
    cin>>k;
    while (k--)
    {
        fill(father,father+maxv,0);
        int n;
        cin>>n;
        while(n--)
        {
            int a,b;
            scanf("%d=%d",&a,&b);
            father[a]=b;
            father[b]=a;
        }
        int m;
        cin>>m;
        while(m--)
        {
            int a;
            cin>>a;
            if(father[a]!=0) cout<<father[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