uva_712-S-Trees

/**先一看题就被吓一跳,到后面才发现题目不怎么难,
 *就是给出一个不超过8层的满二叉树,然后0往左走,1
 *往右走,输入x1,x2……xn(n=depth)
 */
#include <cstdio>
#include <cstring>
#include <cmath>
using namespace std;

#define MAX 1024

char ans[MAX], str[MAX], search[MAX], x[MAX];

int main(int argc, char const *argv[])
{
#ifndef ONLINE_JUDGE
		freopen("test.in", "r", stdin);
#endif
	int 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;
}


  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值