UVA 712 S-Trees

来源:互联网 发布:软件著作权怎么查询 编辑:程序博客网 时间:2024/05/22 21:42
#include <cstdio>#include <cmath>int main() {int t, count = 0;while (scanf("%d", &t), t) {printf("S-Tree #%d:\n", ++count);getchar();char tree[200];gets(tree); //存入x1, x2...gets(tree);//存入树,并且把无用的x1, x2...覆盖掉int n;scanf("%d", &n);for (int i = 0; i < n; i++) {char road[10];scanf("%s", road); //读入路线int sum = 1;for (int j = 0; j < t; j++) //根据路线,计算出位置. 根据的是当前层的两个相邻结点间的距离是 2^(数的深度-当前层数-1)if (road[j] == '1')sum += pow(2, t - j - 1); printf("%c", tree[sum -1]); //输出 tree 的该位置的数}printf("\n\n");}return 0;}


0 0
原创粉丝点击