View Code of Problem 7

#include <cstdio>
#include <algorithm>
using namespace std;

const int maxn = 100010;
int main(){
	int t,n,m;
	int Hash[maxn];
	
	scanf("%d",&t);
	while(t--){
		int a,b;
		scanf("%d",&n);
		fill(Hash,Hash+maxn,0);
		for(int i = 0;i < n;i++){
			scanf("%d=%d",&a,&b);
			Hash[a] = b;
			Hash[b] = a;
		}
		scanf("%d",&m);
		for(int i = 0;i < m;i++){
			int query;
			scanf("%d",&query);
			if(Hash[query] != 0) printf("%d\n",Hash[query]);
			else printf("UNKNOW\n");
		}
		printf("\n");
		 
	}
	return 0;
}

Double click to view unformatted code.


Back to problem 7