Library P97803


Statement
 

pdf   zip

thehtml

Simulate the behavior of the loans of books of a library. According to their theme, there are n different types of books (1, 2, …, n). Initially, we have n stacks with the available books of each type. Afterwards, two different requests may happen:

  • A reader returns a book: We push the book into the stack corresponding to its type. If the given type was not between 1 and n, we ignore the request.
  • A reader asks for a book: We lend the book at the top of the stack of the asked type. If the stack was empty, or if the type was not between 1 and n, we ignore the request.

Input

Input starts with the number of types n (a strictly positive natural number). Follow n lines with the books of each type, given from the bottom of the stack up to the top. Each book is identified with its title (a word). Follows an empty line, and one or more requests, one per line: the word “RETURN” followed by the title and the type (an integer) of the returned book, or the word “LOAN” followed by the type of the asked book (an integer).

Output

Print the content of the n stacks of books, from the bottom of the stack up to its top, following the format of the example.

Observation

The test cases are such that the final stacks are small enough to be printed by a simple recursive procedure, if the case that you program in C++ and you use stack’s.

Public test cases
  • Input

    4
    Christine Tales_of_the_grotesque_and_arabesque
    2001_:_A_space_odissey Do_androids_dream_of_electric_sheep?
    
    The_adventures_of_Sherlock_Holmes Curtain The_murders_in_the_Rue_Morgue
    
    LOAN 1
    LOAN 1
    RETURN Ten_little_niggers 4
    LOAN 2
    LOAN 1
    RETURN Tales_of_the_grotesque_and_arabesque 1
    LOAN 4
    RETURN The_Lord_of_the_Rings 3
    LOAN 4
    RETURN Ten_little_niggers 4
    RETURN Christine 5
    LOAN -3
    LOAN 2
    

    Output

    Stack 1: Tales_of_the_grotesque_and_arabesque
    Stack 2:
    Stack 3: The_Lord_of_the_Rings
    Stack 4: The_adventures_of_Sherlock_Holmes Curtain Ten_little_niggers
    
  • Information
    Author
    Salvador Roura
    Language
    English
    Translator
    Carlos Molina
    Original language
    Catalan
    Other languages
    Catalan
    Official solutions
    C++
    User solutions
    C++ Python