uva_712-S-Trees
[cpp]
/**先一看题就被吓一跳,到后面才发现题目不怎么难,
*就是给出一个不超过8层的满二叉树,然后0往左走,1
*往右走,输入x1,x2……xn(n=depth)
*/
#include <cstdio>
#include <cstring>
#include <cmath>
using namespace std;
#define MAX 1024 www.zzzyk.com
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;
}
补充:软件开发 , Java ,