UVA712 - S-Trees

此題 有規律,本來打算 重新建樹的,但是後來還是放棄了,用下標法。

#include<stdio.h>
#include<string.h>
#include<math.h>
#define N 1000
#define M 10
int main(){
    int t = 1, n, m;

    while (scanf("%d", &n), n){
        char str[N], tem[M], q[M];
        int num[M];
        for (int i = 0; i < n; i++){
            scanf("%s", tem);
            num[i] = tem[1] - '0';
        }
        scanf("%s%d", str,&m);
        for (int i = 0; i < m; i++){
            scanf("%s", tem);
            int k = 0;
            for (int j = 0; j < n; j++)
                k=tem[num[j] - 1] == '1'? (k<<1) + 1:(k<<1);
            q[i] = str[k];
        }
        q[m] = '\0';
        printf("S-Tree #%d:\n%s\n\n", t++, q);
    }
    return 0;
}


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章