View Code of Problem 7

#include<stdio.h>
#include<stdlib.h>
typedef struct{
	int a;
	int b;
}s;
int main() {
	int T;
	scanf("%d",&T);
	for(int i=0;i<T;i++){
		int n;
		scanf("%d",&n);
		s lists[1000];
		for(int j=0;j<n;j++){
			int a,b;
			scanf("%d=%d",&a,&b);
			lists[j].a = a;
			lists[j].b = b;
		}
		int m;
		scanf("%d",&m);
		for(int j=0;j<m;j++){
			int search; 
			scanf("%d",&search);
			int result,k,flag;
			flag=0;
			for(k=0;k<n;k++){
					if(lists[k].a == search){
						result = lists[k].b;
						flag=1;
						break;
					}else if(lists[k].b == search){
						result = lists[k].a;
						flag=1;
						break;
					}
				}
				if(flag==0){
					printf("UNKNOW\n");
				}else{
					printf("%d\n",result);
				}
			}
			
		}
		printf("\n");
return 0;
	}
	

Double click to view unformatted code.


Back to problem 7