uva 712 二叉树
程序员文章站
2022-03-14 19:33:26
...
好好读题,尤其是input,关于xi会有一个对应关系,Eg:第一行输入x3, x2, x1, 然后输入100,那么实际要操作的指令是001
#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
using namespace std;
int main()
{
//freopen("ztest.txt","r",stdin);
//freopen("zans.txt","w",stdout);
int t;
string str, str1;
int c = 1;
while(scanf("%d", &t) && t)
{
int num[1000000];
printf("S-Tree #%d:\n",c++);
getchar();
getline(cin, str);
int k = 0;
for(int i = 0; i < str.size(); i++)
{
if(str[i] >= '1' && str[i] <= '9')
num[k++] = str[i]-'0';
}
cin >> str;
//cout << str << endl;
int n;
scanf("%d", &n);
for(int i = 1; i <= n; i++)
{
string str2;
cin >> str2;
str1 = str2;
for(int i = 0; i < str2.size(); i++)
str1[i] = str2[num[i]-1];
int bit = 0;
for(int i = 0; i < str1.size(); i++)
{
if(str1[i] - '0')
bit = bit*2+1;
else
bit = bit*2;
}
printf("%c",str[bit]);
}
printf("\n\n");
}
return 0;
}
下一篇: 都比你做的好吃