P29884 [洛谷] [LanQiao Cup 2013 National C] Horizontal Print Binary Tree
提高-
题目描述

Background

Binary trees can be used for sorting.

Problem Description

The principle is simple: when adding a new node to a sorted binary tree, compare it with the root node. If it is smaller, pass it to the left subtree to continue processing; otherwise, pass it to the right subtree.

When an empty subtree is encountered, place the node in that position.

For example, the input sequence 10 8 5 7 12 4 should form a binary tree as shown in Figure $1$.

This problem requires: based on the given numbers, to build a sorted binary tree and print the tree horizontally on the standard output.

Input Format

The input data consists of one line of space-separated integers. $N < 100$, and each number does not exceed $10000$.

$N$ is not given in the input.

There are no duplicate numbers in the input data.

Output Format

Output the horizontal representation of the sorted binary tree. To facilitate the comparison of spaces by the judging program, replace spaces with dots.

Sample Input and Output

Sample Input #1

10 8 5 7 12 4

Sample Output #1

...|-12
10-|
...|-8-|
.......|...|-7
.......|-5-|
...........|-4

Sample Input #2

10 5 20

Sample Output #2

...|-20
10-|
...|-5

Sample Input #3

5 10 20 8 4 7

Sample Output #3

.......|-20
..|-10-|
..|....|-8-|
..|........|-7
5-|
..|-4

Notes

Sample Explanation 1:

Time Limit: 1 second, Memory Limit: 64M. LanQiao Cup 2013, 4th National Finals.

输入格式

见题面 Input 部分

输出格式

见题面 Output 部分

样例输入
10 8 5 7 12 4
样例输出
...|-12 10-| ...|-8-| .......|...|-7 .......|-5-| ...........|-4