#T86. 二叉树输出
二叉树输出
Description
The indentation representation of a tree is primarily used for on-screen or printed output. Its basic principle is that siblings are of equal length, and the length of a node must not be less than the length of its child nodes. A binary tree can also be represented this way, assuming the length of a leaf node is 1, and the length of a non-leaf node equals the sum of the lengths of its left and right subtrees.
Each node of a binary tree is represented by a unique letter. The output starts from the root node:
Each line outputs a certain number of node characters (the count of identical characters equals the length of the node).
If the node has a left subtree, recursively output the left subtree.
If the node has a right subtree, recursively output the right subtree.
Assume each node of the binary tree is described by a single character. Given the strings for the preorder and inorder traversals, output the binary tree using the indentation representation method.
Input Format
Two lines, each consisting of a string of unique letters, representing the preorder and inorder traversal sequences of the binary tree, respectively.
Output Format
The number of lines equals the number of nodes in the tree, with each line consisting of identical letters.
ABCDEFG
CBDAFEG
AAAA
BB
C
D
EE
F
G