Left child, right sibling (3) P24438


Statement
 

pdf   zip

html

Write a program that reads a general tree of words, and prints its corresponding binary tree following the format of the exercise : “”.

Input

Input consists of the description of a tree of words as is explained at the exercise : “”. All the words have less than ten letters.

Output

Your program must print the binary tree corresponding to the general tree following the format of the exercise : “”.

From the general tree, the associated binary tree can be written directly. Therefore, is not necessary to construct it explicitly.

Public test cases
  • Input

    12
    january 3
    february 0
    march 2
    april 1
    may 1
    june 0
    july 0
    august 4
    september 0
    october 0
    november 0
    december 0
    

    Output

       january
                                      august
                                                                            december
                                                                  november
                                                         october
                                             september
                             march
                                                  july
                                       april
                                                   may
                                                            june
                february
    
  • Information
    Author
    Salvador Roura
    Language
    English
    Translator
    Carlos Molina
    Original language
    Catalan
    Other languages
    Catalan
    Official solutions
    C++
    User solutions