Simulate the behavior of the loans of books of a library. According to their theme, there are different types of books (). Initially, we have 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 , 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 , we ignore the request.
Input starts with the number of types
(a strictly positive natural number). Follow
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).
Print the content of the stacks of books, from the bottom of the stack up to its top, following the format of the example.
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.
Author: Unknown
Translator: Carlos Molina
Generation: 2026-01-25T12:15:28.511Z
© Jutge.org, 2006–2026.
https://jutge.org