UVA 712 S-tree
#include<iostream> #include<string> #include<string.h> #include<stack> #include<math.h> #include<stdio.h> using namespace std; int main(){ int n,t; char leaf[200],serch[200],ss[200],res[200]; char a[5]; int b[20],num=0; while(cin>>n){ if(n==0) break; num++; memset(a,0,sizeof(a)); memset(leaf,0,sizeof(leaf)); memset(serch,0,sizeof(serch)); memset(ss,0,sizeof(ss)); memset(b,0,sizeof(b)); int j=0; for(int i=0;i<n;i++){ cin>>a; b[j++]=a[1]-'0'; } cin>>leaf; cin>>t; int p=0; memset(res,0,sizeof(res)); while(t--){ cin>>ss; for(int i=0;i<n;i++){ serch[i]=ss[b[i]-1]; } int sum=0; for(int i=n-1;i>=0;i--){ sum+=(serch[i]-'0')*pow(2,n-1-i); } res[p++]=leaf[sum]; // cout<<leaf[sum]<<endl; } cout<<"S-Tree #"<<num<<":"<<endl; cout<<res<<endl; cout<<endl; } return 0; }