Skip to content

Instantly share code, notes, and snippets.

@KT-Yeh
Created February 28, 2014 11:10
Show Gist options
  • Select an option

  • Save KT-Yeh/9269278 to your computer and use it in GitHub Desktop.

Select an option

Save KT-Yeh/9269278 to your computer and use it in GitHub Desktop.
#include <iostream>
#include <cstdio>
#include <string>
#include <vector>
using namespace std;
int main()
{
// freopen("input.txt","rt",stdin);
ios::sync_with_stdio(false);
int N, M, Case = 1;
while (cin >> N && N) {
cout << "S-Tree #" << Case++ << ':' << endl;
string tmp;
vector<int> order;
string terminal_node;
for (int i = 0; i < N; ++i) {
cin >> tmp;
order.push_back(tmp[1]-'0');
}
cin >> terminal_node >> M;
string VVA;
while (M--) {
cin >> VVA;
int node_num = 0;
for (int i = 0; i < N; ++i) {
int direction = VVA[order[i]-1] - '0';
node_num = node_num * 2 + direction;
}
cout << terminal_node[node_num];
}
cout << endl << endl;
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment