习题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;
}
上一篇: 二分查找:比较次数
下一篇: 二分查找递归、非递归实现比较(Java)