uva_712-S-Trees

来源:互联网 发布:淘宝苹果电脑有假货吗 编辑:程序博客网 时间:2024/05/17 07:35
/**先一看题就被吓一跳,到后面才发现题目不怎么难, *就是给出一个不超过8层的满二叉树,然后0往左走,1 *往右走,输入x1,x2……xn(n=depth) */#include <cstdio>#include <cstring>#include <cmath>using namespace std;#define MAX 1024char ans[MAX], str[MAX], search[MAX], x[MAX];int main(int argc, char const *argv[]){#ifndef ONLINE_JUDGEfreopen("test.in", "r", stdin);#endifint depth, cas, cnt(1);char c;while( ~scanf("%d", &depth) ){    if( !depth ) return 0;memset(ans, '\0', sizeof(ans));for(int i = 0; i < depth; i ++){    getchar();scanf("%c%d", &c, &x[i]);}scanf("%s", str);scanf("%d", &cas);for(int i = 0, pos; i < cas; i ++){    pos = 0;scanf("%s", search);for(int j = 0; j < depth; j ++){    if(search[x[j]-1] - '0')                    pos += pow(2, depth-j-1);}ans[i] = str[pos];}printf("S-Tree #%d:\n", cnt++);puts(ans);printf("\n");}return 0;}


原创粉丝点击