UVA 712-s-trees
The main topic: give a certain depth of the slow binary tree, each leaf node corresponding value, give the path, the output of the value, 0 is the left subtree, 1 is the right sub-tree
The idea of solving problems: Using POW (2,n) to make it easy to get the last position of the path
#include <stdio.h> #include <iostream> #include <string> #include <sstream> #include <math.h
> Using namespace std;
int main () {int n;
int g = 0;
while (CIN >> n && n! = 0) {g++;
GetChar ();
int a[10];
for (int i = n-1; I >= 0; i--) {int k;
GetChar ();
Cin >> K;
A[k] = i;
GetChar ();
} Char s[1000];
Gets (s);
int m;
int b[1000];
Cin >> m;
GetChar ();
for (int i = 0; i < m; i++) {int s = 0;
Char s2[1000];
Gets (S2);
for (int j = 1; J <= N; j + +) {s = s + (s2[j-1]-' 0 ') * POW (2, a[j]);
} B[i] = s;
} printf ("S-tree #%d:\n", g);
for (int i = 0; i < m; i++) {printf ("%c", S[b[i]]);
} printf ("\ n");
} return 0;
}