UVA 712 - S-Trees(二)

2015-07-24 07:08:12 · 作者: · 浏览: 108
alue of x1, the second character describes the value of x2, and so on. So, the line

110

corresponds to the VVA (x1 = 1, x2 = 1, x3 = 0).

The input is terminated by a test case starting with n = 0. This test case should not be processed.

Output

For each S-tree, output the line `` S-Tree # j :", where j is the number of the S-tree. Then print a line that contains the value of $f(x_1, x_2, \dots, x_n)$for each of the given m VVAs, where f is thefunction defined by the S-tree.

Output a blank line after each test case.

Sample Input

3
x1 x2 x3
00000111
4
000
010
111
110
3
x3 x1 x2
00010011
4
000
010
111
110
0

Sample Output

S-Tree #1:
0011

S-Tree #2:
0011

只要把题意搞清楚了这道题还是很简单的,按照正常思路先建树再遍历,直接模拟即可。遍历的时候遍历两次,第一次赋值,第二次得出结果,输入的时候我是把X忽略,根据X的下标确定每个节点的位置,然后在遍历赋值的时候就可以根据这个下标给节点赋值。把建树放在循环中使每次的数据互不干扰。

AC的代码如下: