View Code of Problem 7

#include <stdio.h>
#include <malloc.h>
#define MAX 10000
int p[MAX];
int q[MAX];
int main()
{
    int t, n, m, a, b, temp, i, j, pos = 0;
	scanf("%d",&t);
	for (i=0; i<t; i++)
    {
        scanf("%d", &n);
        for (j=0; j<MAX; j++)
        {
            p[j] = 0;
        }
        for (j=0; j<n; j++)
        {
            scanf("%d=%d", &a, &b);
            p[a] = b;
            p[b] = a;
        }
        scanf("%d",&m);
        for (j=0; j<m; j++)
        {
            scanf("%d",&temp);
            if (temp != 0)
                q[pos] = p[temp];
            else
                q[pos] = 0;
            pos++;
        }
        q[pos] = -1;
        pos++;
    }
    pos--;
    for (i=0; i<pos; i++)
    {
        if (q[i] == 0)
            printf("UNKNOW\n");
        else
            if (q[i] == (-1))
            printf("\n");
        else
            printf("%d\n",q[i]);
    }
    return (0);
}

Double click to view unformatted code.


Back to problem 7