S-Trees UVA - 712
程序员文章站
2024-03-18 21:50:28
...
#include <iostream>
#include <bits/stdc++.h>
#define maxn 100
using namespace std;
int n,m;
int v[maxn];
string leave,q;
void solve(string s)
{
int layer = 1;
for(int i = 0;i<n;i++)
{
if(q[v[i]]=='0')//向左边走
{
layer = 2*layer;
}
else
{
layer = 2*layer + 1;
}
}
layer -= (1<<n);
cout<<leave[layer];
}
int main()
{
string s;
int kase = 1;
while(cin>>n&&n)
{
cout<<"S-Tree #"<<kase++<<":"<<endl;
for(int i = 0;i<n;i++)
{
cin>>s;
v[i] = s[1]-'1';
}
cin>>leave>>m;
while(m--)
{
cin>>q;
solve(q);
}
cout<<endl;
cout<<endl;
}
return 0;
}
/**
3
x1 x2 x3
00000111
4
000
010
111
110
3
x3 x1 x2
00010011
4
000
010
111
110
0
**/
上一篇: 信息学奥赛一本通 1924:【03NOIP普及组】栈
下一篇: PIZZATO FD535-2