View Code of Problem 7

#include<iostream>
#include<cstdio>
#include<string>
#include<cstring>
#include<cstdlib>
#include<algorithm>
using namespace std;

char str[100000010],str1[100000],str2[100000];
int a[100000],b[100000];
int main()
{
    int n,n1,n2;
    scanf("%d",&n);
    while(n--)
    {
        memset(str,0,sizeof(str));
        memset(a,-1,sizeof(a));
        memset(b,-1,sizeof(b));
        scanf("%d",&n1);
        for(int i = 0;i < n1;i++)
        {
            int flag,j,mm;
            scanf("%s",str);
            for(j = 0;str[j]!= 0;j++)
            {
                if(str[j]== '=')
                    flag = j;
            }
            for(j = 0; j< flag;j++)
                str1[j] = str[j];
            str[j] = 0;
            mm = 0;
            for(j = flag+1;str[j]!=0;j++)
                str2[mm++] = str[j];
            str2[mm] = 0;
            a[atoi(str1)] = atoi(str2);
            a[atoi(str2)] = atoi(str1);
        }
        scanf("%d",&n2);
        for(int i = 0;i < n2;i++)
        {
            scanf("%d",&n1);
            if(a[n1]!=-1)
                printf("%d\n",a[n1]);
            else
                printf("UNKNOW\n");
        }
        if(n==0)
            printf("\n");
    }
}

Double click to view unformatted code.


Back to problem 7