#include <stdio.h> #include <string.h> #include <math.h> #include <stdlib.h> #define PR printf #define SC scanf #define D "%ld" int main(){ long t, n[32]; long i, j, k, l, tot; long key[1000000][4]; long que[1000000]; long ans[1000000][512]; char s[128], c[128]; //system("color 0f"); SC(D, &t); for (i = 0; i < t; i++) { SC(D, &tot); for (j = 0; j < tot; j++) { scanf("%s", s); for (k = 0; k < strlen(s); k++){ if (s[k] == '=') { strcpy(c, "0"); strncpy(c, s, k); key[j][0] = atoi(c); //PR("%s", c); //PR("%ld\n", key[j][0]); strcpy(c, "0"); strncpy(c, s + k + 1, strlen(s) - k - 1 ); key[j][1] = atoi(c); //PR("%s", c); //PR("%ld\n", key[j][1]); } } } SC(D, &n[i]); for (j = 0; j < n[i]; j++) SC(D, &que[j]); for (j = 0; j < n[i]; j++) ans[i][j] = -1; for (j = 0; j < n[i]; j++) { for (l = 0; l < tot; l++) { //PR("%ld, ", que[j]); if (key[l][0] == que[j]) { //PR("找到%ld\n", key[l][0]); ans[i][j] = key[l][1]; break; } if (key[l][1] == que[j]) { //PR("找到%ld\n", key[l][1]); ans[i][j] = key[l][0]; break; } //PR("再找\n"); } } } for (i = 0; i < t; i++) { for (j = 0; j < n[i]; j++) { if (ans[i][j] != -1) PR(D "\n", ans[i][j]); else PR("UNKNOW\n"); } PR("\n"); } return 0; } |
Double click to view unformatted code.