View Code of Problem 7

#include <stdio.h>
#include <stdlib.h>

int a[100005];

int main()
{
    int t, n, c, s, p, m;
    scanf("%d", &t);
    c = 0;
    while (t--)
    {
        if (c != 0)
        {
            printf("\n");
        }
        c++;
        for (int i = 0; i < 100005; i++)
        {
            a[i] = -1;
        }
        scanf("%d", &n);
        for (int i = 0; i < n; i++)
        {
            scanf("%d=%d", &s, &p);
            a[s] = p;
            a[p] = s;
        }
        scanf("%d", &m);
        while (m--)
        {
            scanf("%d", &s);
            if (s < 0 || s > 100000 || a[s] == -1)
                printf("UNKNOW\n");
            else printf("%d\n", a[s]);
        }
    }
}

Double click to view unformatted code.


Back to problem 7