View Code of Problem 7

#include<stdio.h>
int main()
{
	int t;
	int n;
	int m;//需要查询m个数
	int a[1000],b[1000];
	int c[1000];
	int i,j; //for循环的 
	int flag;
	scanf("%d",&t);
	getchar();
	while(t>0)
	{
		scanf("%d",&n); //表示有n行等式
		for(i=0;i<n;i++)
		{
			scanf("%d=%d",&a[i],&b[i]);
		}
		
		scanf("%d",&m);
		//输入m个数到c中 
		for(i=0;i<m;i++)
		{
			scanf("%d",&c[i]);
		}
		
		for(i=0;i<m;i++)
		{
			flag=0;
			for(j=0;j<n;j++)
			{
				if(c[i]==a[j])
				{
					printf("%d\n",b[j]);
					flag=1;
					break;
				}
				 if(c[i]==b[j])
				{
					printf("%d\n",a[j]);
					flag=1;
					break;
					
				}
			}
			if(flag==0)
				printf("UNKNOW\n");	
		}
		printf("\n");
		t--;
	}
	return 0;
}

Double click to view unformatted code.


Back to problem 7