[Cpp]
/** The question is scared at first glance. It is not difficult to find the question at the end,
* A full binary tree with no more than eight layers is provided, and then 0 goes to the left, 1
* Go to the right and enter x1, x2 ...... Xn (n = depth)
*/
# Include <cstdio>
# Include <cstring>
# Include <cmath>
Using namespace std;
# Define MAX 1024 www.2cto.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;
}