This page is still under construction.

Parts of this page are still being built. What you see may change.

JAG-channel

Interview

Time limit8sMemory limit512 MB

Summary
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.

nn

s1s_1

s2s_2

...

sns_n

nn is an integer representing the number of lines of the simple format display, and you may assume 1≤n≤1,0001 \le n \le 1{,}000. The following nn lines contain the simple format display of the thread tree. sis_i represents the ii-th line of the simple format display and consists of several '.' followed by a string of 1 to 50 lowercase alphabet letters. s1s_1 is the first post of the thread and contains no '.'. s2s_2, ..., sns_n are replies in that thread and always contain at least one '.'.

n=0n=0 indicates the end of the input. This is not included in the data sets.

Output

For each data set, output the formatted display in nn lines.

Examples1

  1. Example 1

    Input
    6
    hoge
    .fuga
    ..foobar
    ..jagjag
    ...zigzag
    .piyo
    8
    jagjag
    .hogehoge
    ..fugafuga
    ...ponyoponyo
    ....evaeva
    ....pokemon
    ...nowawa
    .buhihi
    8
    hello
    .goodmorning
    ..howareyou
    .goodafternoon
    ..letshavealunch
    .goodevening
    .goodnight
    ..gotobed
    3
    caution
    .themessagelengthislessthanorequaltofifty
    ..sothelengthoftheentirelinecanexceedfiftycharacters
    0
    
    Expected output
    hoge
    +fuga
    |+foobar
    |+jagjag
    | +zigzag
    +piyo
    jagjag
    +hogehoge
    |+fugafuga
    | +ponyoponyo
    | |+evaeva
    | |+pokemon
    | +nowawa
    +buhihi
    hello
    +goodmorning
    |+howareyou
    +goodafternoon
    |+letshavealunch
    +goodevening
    +goodnight
     +gotobed
    caution
    +themessagelengthislessthanorequaltofifty
     +sothelengthoftheentirelinecanexceedfiftycharacters