View Code of Problem 7

#include <iostream>
#include <cstring>
using namespace std;
int t,n,m,a[1000010];
int main(){
	cin>>t;
	while(t--){
		cin>>n;
		string s;
		while(n--){
			cin>>s;
			int index=s.find("="),b=0,c=0;
			for(int i=0;i<index;i++){
				b+=s[i]-'0';
				b*=10;
			}
			for(int j=index+1;j<s.length();j++){
				c+=s[j]-'0';
				c*=10;
			}
			a[b/10]=c/10;
			a[c/10]=b/10;
		}
		cin>>m;
		while(m--){
			int x;
			cin>>x;
			if(a[x]==0)
				cout<<"UNKNOW"<<endl;
			else
				cout<<a[x]<<endl;
		}
		cout<<endl;
		memset(a,0,sizeof(a));
	}
	return 0;
}

Double click to view unformatted code.


Back to problem 7