Trees - Printing a tree P21036


Statement
 

pdf   zip

thehtml

Write a program that reads a binary tree of words, and that prints it following the format of the sample.

Input

Input consists of the description of a tree, which is a preorder traversal of its words, marking the empty trees with ‘-1’- You can assume that the given words have less than ten letters.

Output

Your program must print the tree following the format of the sample. Notice that each level of the tree is printed using ten characters.

Public test cases
  • Input

    va tenir sis -1 polls -1 -1 xics -1 -1 pics
    pellarics -1 -1 camatorts i -1 becarics -1 -1 -1
    

    Output

                         camatorts
                                              becarics
                                           i
                    pics
                         pellarics
            va
                              xics
                   tenir
                                       polls
                               sis
    
  • Information
    Author
    Jordi Petit i Salvador Roura
    Language
    English
    Translator
    Jordi Petit
    Original language
    Catalan
    Other languages
    Catalan
    Official solutions
    C++ Python
    User solutions
    C++ Python