JAG-channel
InterviewTime limit8sMemory limit512 MB
Each line is a post indented by dots; redraw the dots as spaces, mark each post's own dot with '+', and draw '|' between a parent and its descendants.
- Level
Medium5 of 10
- Topics
- Implementation, Tree, Simulation, Stack
- Solved
- No attempts yet
Problem
Nathan O. Davis runs an electronic bulletin board called JAG-channel. He is currently working on adding a new feature called thread view.
Like most electronic bulletin boards, JAG-channel is thread-based. A thread is a group of posts that form a single conversation. There are two kinds of posts:
- The first post, which creates a new thread
- A reply to an earlier post in an existing thread
Thread view is a tree-shaped view that represents the logical structure of replies between posts. Each post is a node of the tree, and its children are the replies to that post. Note that the direct and indirect replies to a post form a subtree as a whole.
Consider an example. Suppose the first post "hoge" gets two replies, "fuga" and "piyo", "fuga" in turn gets the replies "foobar" and "jagjag", and "jagjag" gets the reply "zigzag". The tree for this thread looks like this.
hoge
├─fuga
│ ├─foobar
│ └─jagjag
│ └─zigzag
└─piyo
Nathan O. Davis hired a programmer to implement the feature, but the programmer disappeared at the last stage. The programmer had finished building the thread tree and displaying it in a simple format. In this simple format, the depth of a reply is shown by '.' (a half-width period), and a reply to a post has one more '.' on its left than the original post. A reply to a post always comes below the original post. Between a post and its reply, other replies to the post (and their direct and indirect replies) may appear, but no other post appears between the two. The simple format display of the tree above looks like this.
hoge
.fuga
..foobar
..jagjag
...zigzag
.piyo
Your job is to take this simple format display and format it more readably. Specifically, replace
- the '
.' immediately to the left of each post (the rightmost of the '.' on the left of that post) with '+' (a half-width plus), - for each direct reply to the same post, the '
.' located between the '+' immediately to the left of each such reply with '|' (a half-width vertical bar), - all other '
.' with '' (a half-width space).
The formatted display of the simple format above looks like this.
hoge
+fuga
|+foobar
|+jagjag
| +zigzag
+piyo
Input
The input consists of multiple data sets. The format of each data set is as follows.
...
is an integer representing the number of lines of the simple format display, and you may assume . The following lines contain the simple format display of the thread tree. represents the -th line of the simple format display and consists of several '.' followed by a string of 1 to 50 lowercase alphabet letters. is the first post of the thread and contains no '.'. , ..., are replies in that thread and always contain at least one '.'.
indicates the end of the input. This is not included in the data sets.
Output
For each data set, output the formatted display in lines.