Navigating a tree P64456


Statement
 

pdf   zip

html

Write a program that reads a non empty binary tree of words, places at the root of the tree, and then moves in the tree followings the orders that is given.

Input

Input starts with the description of a non empty tree as is explained at the exercise : “”. Afterwards, a sequence of words that can be "up", "left" or "right" comes.

Output

Your program must print the content of the initial position, and of the position after each step. The order that would cause to go out of the tree must be ignored, but writing the content of the position.

Public test cases
  • Input

    10
    betty and bob -1 brought -1 -1 back -1 -1 blue
    balloons -1 -1 from the -1 bazaar -1 -1 -1
    
    left
    right
    left
    up
    up
    up
    right
    right
    right
    left
    right
    left
    

    Output

    betty
    and
    back
    back
    and
    betty
    betty
    blue
    from
    from
    the
    bazaar
    bazaar
    
  • Information
    Author
    Salvador Roura
    Language
    English
    Translator
    Carlos Molina
    Original language
    Catalan
    Other languages
    Catalan
    Official solutions
    C++
    User solutions
    C++ Python