Original title:
The topic is too long, not posted online.
topic:
give you a number n, tell you that this is an n-level complete binary tree, each layer corresponds to a letter Xi, and then give you a string to represent the value of the leaf point. Next I'll give you a number m, with M query string, only 0 and 1 in each string, where 0 means go from root to Zuozi, 1 is right. Finally ask you m query to the value of the leaf node to make up a string is how much.
#include <iostream> #include <algorithm> #include <map> #include <string> #include <cstring > #include <sstream> #include <cstdio> #include <vector> #include <cmath> #include <stack > #include <queue> #include <iomanip> #include <set> #include <fstream> #include <limits.h
> Using namespace std;
FStream output,input;
int tree[1024];
int n,m;
Vector<int> ans;
int main () {Ios::sync_with_stdio (false);
string S;
int tmp,x=1;
while (cin>>n,n) {memset (tree,-1,sizeof (-1));
Ans.clear ();
for (int i=0;i<n;i++) cin>>s;
cin>>s;
int k= (int) pow (2,n);
for (int i=0;i<s.size (); i++) tree[k+i]=s[i]-' 0 ';
cin>>m;
for (int i=0;i<m;i++) {cin>>s;
Tmp=1;
for (int j=0;j<s.size (); j + +) {if (s[j]== ' 0 ') tmp*=2;
else tmp=tmp*2+1;
} ans.push_back (Tree[tmp]);
} cout<< "S-tree #" <<x++<< ":" <<endl;
for (int i=0;i<ans.size (); i++) cout<<ans[i];
cout<<endl;
cout<<endl;
} return 0;
}
Answer:
When I just read it, I was really scared and I thought it was going to be a lot of effort. After reading the feeling this problem is a waste problem, do not build, directly with the array storage can. The input of each XI value is not used, the last traversal of the query string if it is 0 means to left to let tmp*2, go to the right to let tmp*2+1d, finally to the leaf node, the value can be removed.