712 - S-Trees (UVA)

题目链接如下:

Online Judge

我的代码如下:

#include 
// #define debug

int n, m, kase = 0;
char loc[3], terminal[130], vva[8];
int order[7];

int main(){
    #ifdef debug
    freopen("0.txt", "r", stdin);
    freopen("1.txt", "w", stdout);
    #endif
    while (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 debug
    fclose(stdin);
    fclose(stdout);
    #endif
    return 0;
}

你可能感兴趣的:(UVA,算法)