欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

习题6_2 S树(S-Trees, UVa712)

程序员文章站 2022-03-01 18:43:56
...

AC代码:

#include<cstdio>
#include<cstring>

int n, m;
char x[7][4];
char s[1<<7], s2[1<<7];

int main() {
	#ifdef LOCAL
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
	#endif
	int kase = 0;
	while(scanf("%d", &n) == 1 && n) {
		printf("S-Tree #%d:\n", ++kase);
		for(int i = 0; i < n; i++) scanf("%s", x[i]);
		scanf("%s", s);
		scanf("%d", &m);
		while(m--) {
			scanf("%s", s2);
			int len = strlen(s2);
			int k = 1;
			for(int i = 0; i < len; i++) {
				if(s2[i] == '1') k = 2*k + 1;
				else k = 2*k;
			}
			printf("%c", s[k-(1<<n)]);
		}
		printf("\n\n");
	}
	return 0;
}