View Code of Problem 7

    #include<stdio.h>
    int main()
    {
    	int T,m,i,k,n,j,leap;
    	int a[1000];
    	int b[1000];
    	int c[1000];
    	scanf("%d", &T);
    	for (i = 0; i < T; i++)
    	{
    		scanf("%d", &m);
    		for (k = 0; k < m; k++)
    		{
    			scanf("%d=%d", &a[k], &b[k]);
    		}
    		scanf("%d", &n);
    		for (j = 0; j < n; j++)
    		{
    			scanf("%d", &c[j]);
    		}
    		for (j = 0; j < n; j++)
    		{
    			leap = 0;
    			for (k = 0; k < m; k++)
    			{
    				if (c[j] == a[k])
    				{
    					printf("%d\n", b[k]);
    					leap = 1;
    					break;
    				}
    				if (c[j] == b[k])
    				{
    					printf("%d\n", a[k]);
    					leap = 1;
    					break;
    				}
    			}
    			if (leap == 0)
    			{
    				printf("UNKNOW\n");
    			}
    		}
    		printf("\n");
    	}
    }

Double click to view unformatted code.


Back to problem 7