题目链接如下:
Online Judge
我的代码如下:
#include <cstdio>
// #define debugint n, m, kase = 0;
char loc[3], terminal[130], vva[8];
int order[7];int main(){#ifdef debugfreopen("0.txt", "r", stdin);freopen("1.txt", "w", stdout);#endifwhile (scanf("%d", &n) == 1 && n){printf("S-Tree #%d:\n", ++kase);for (int i = 0; i < n; ++i){scanf("%s", loc);order[i] = loc[1] -'1';}scanf("%s", terminal);scanf("%d", &m);while (m--){scanf("%s", vva);int k = 0;for (int i = 0; i < n; ++i){k = 2 * k + vva[order[i]] - '0';}printf("%c", terminal[k]);}printf("\n\n");}#ifdef debugfclose(stdin);fclose(stdout);#endifreturn 0;
}