712 - S-Trees

 1 #include<iostream>
 2 #include<stdio.h>
 3 #include<string>
 4 using namespace std;
 5 int result[128];
 6 int ans[200];
 7 int count=1;
 8 int main()
 9 {
10     int n;
11     while(cin>>n)
12     {
13         if(n==0)
14             break;
15         getchar();
16         string str;
17         getline(cin,str);
18         int i;
19         for(i=0;i<(1<<n);i++)
20         result[i]=getchar()-'0';
21         int m;
22         cin>>m;
23         getchar();
24         for(i=0;i<m;i++)
25         {
26             getline(cin,str);
27             int sum=0;
28             int j=-1;
29             while(++j<str.length())
30                 sum=2*sum+str[j]-'0';
31             ans[i]=result[sum];
32         }
33         cout<<"S-Tree #"<<count++<<":"<<endl;
34         for(i=0;i<m;i++)
35             cout<<ans[i];
36         cout<<endl;
37         cout<<endl;
38     }
39     return 0;
40 }
41      
42             

 

 

posted @ 2013-03-31 00:07  sooflow  阅读(129)  评论(0)    收藏  举报