View Code of Problem 7

#include <stdio.h>

int main(){
    int T,n,a,b,m,u[1000000][2],key;
    bool success = true;
    char c;
    scanf("%d",&T);
    printf("\n");
    while(T--){
        scanf("%d",&n);
        for(int i=0;i<n;i++){
            scanf("%d%c%d",&a,&c,&b);
            u[i][0] = a;
            u[i][1] = b;
        }
        scanf("%d",&m);
        for(int i=0;i<m;i++){
            scanf("%d",&key);
            for(int j=0;j<n;j++){
                if(u[j][0] == key){
                    printf("%d\n",u[j][1]);
                    success = false;
                    break;
                }
                else if(u[j][1] == key){
                    printf("%d\n",u[j][0]);
                    success = false;
                    break;
                }
            }
            if(success){
                printf("UNKNOW");
            }
            success = true;
        }
        printf("\n");

    }
}

Double click to view unformatted code.


Back to problem 7