二叉树? 怒水~~
注意一下查询与x值的对应关系就好~
1 #include <iostream> 2 #include <cstring> 3 #include <cstdio> 4 using namespace std; 5 6 int main (){ 7 char s[1000]; 8 int a[10],b[10]; 9 int n; 10 int m; 11 int kase=0; 12 while (~scanf ("%d",&n)&&n){ 13 char c[10]; 14 for (int i=0;i<n;i++){ 15 scanf ("%s",c); 16 a[i]=c[1]-‘0‘;//cout<<a[i]<<"eee"; 17 } 18 scanf ("%s",s); 19 scanf ("%d",&m); 20 printf ("S-Tree #%d:\n",++kase); 21 for (int i=0;i<m;i++){ 22 scanf ("%s",c); 23 int temp=0; 24 for (int j=0;j<n;j++){ 25 b[j]=c[a[j]-1]-‘0‘; 26 temp=temp*2+b[j]; 27 } 28 printf ("%c",s[temp]);//cout<<temp<<"er"<<endl; 29 } 30 printf ("\n\n"); 31 } 32 return 0; 33 }
UVA 712 S-Trees,布布扣,bubuko.com
原文地址:http://www.cnblogs.com/gfc-g/p/3860833.html