View Code of Problem 7

#include <stdio.h>
#define MAX 1000
int main()
{
    int p[MAX];
    int q[MAX];
    int tem[MAX];
    int t, n, m;
    int a, b, temp;
    int i, j, k;
    int flag;//非0时有可转换的数据
    int pos = 0;

    scanf("%d",&t);//T组输入
    for (i=0; i<t; i++)
    {
        //读入等式
        scanf("%d", &n);//n行等式
        for (j=0; j<n; j++)
        {
            scanf("%d=%d", &a, &b);
            p[j] = a;
            p[2*n-1-j] = b;
        }

        //读入测试数据
        scanf("%d",&m);//m组数据
        for (j=0; j<m; j++)
            scanf("%d",&tem[j]);
        for (j=0; j<m; j++)
        {
            flag = 0;

            for (k=0; k<n*2; k++)
            {
                if (tem[j] == p[k])
                {
                    flag = 1;
                    break;
                }
            }

            if (flag)
                printf("%d\n", p[2*n-k-1]);
                else
                    printf("UNKNOW\n");
            pos++;
        }
        printf("\n");
        //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]);
    }*/
    //printf("%d\n",pos);
    return (0);
}

Double click to view unformatted code.


Back to problem 7