forked from daiwb/Algorithm
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path1150S-Trees.cpp
More file actions
55 lines (50 loc) · 830 Bytes
/
1150S-Trees.cpp
File metadata and controls
55 lines (50 loc) · 830 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
/**
* ZOJ 1150 S-Trees
*
* 05/03/29 by adai
*/
#include <iostream>
using namespace std;
#ifdef WIN32
#define for if(0); else for
#endif
int n, kase;
int seq[7];
int terminal[128];
int b[7];
int Run() {
for (int i = 0; i < n; ++i) {
char sequence[3];
cin >> sequence;
seq[i] = sequence[1] - '1';
}
int total = 1 << n;
char temp[129];
cin >> temp;
for (int i = 0; i < total; ++i) {
terminal[i] = temp[i] - '0';
}
cout << "S-Tree #" << ++kase << ":" << endl;
int num;
cin >> num;
while (num--) {
int pos = 0;
cin >> temp;
for (int i = 0; i < n; ++i) {
b[i] = temp[i] - '0';
}
for (int i = 0; i < n; ++i) {
if (b[seq[i]]) pos = pos * 2 + 1;
else pos *= 2;
}
cout << terminal[pos];
}
cout << endl << endl;
return 0;
}
int main() {
while (cin >> n && n) {
Run();
}
return 0;
}