Library

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.

Problem information

Author: Unknown
Translator: Carlos Molina

Generation: 2026-01-25T12:15:28.511Z

© Jutge.org, 2006–2026.
https://jutge.org
