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

AC代码:

#include
#include

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;
}

你可能感兴趣的:(算法竞赛,二叉树,算法,数据结构)