#K77867. Book Borrowing Management System

    ID: 34960 Type: Default 1000ms 256MiB

Book Borrowing Management System

Book Borrowing Management System

You are given a set of commands simulating operations within a book borrowing system. The system supports three types of operations:

  • B u b: The user with id u borrows the book with id b.
  • R u b: The user with id u returns the book with id b. A return operation only removes the record if the book is currently borrowed by that user.
  • C b: Check the status of the book with id b. If the book is currently borrowed, output the id of the user who borrowed it; otherwise, output available.

Input consists of one or more datasets. Each dataset begins with an integer n indicating the number of commands, followed by n commands (one per line). The input terminates with a line containing a single zero (0), which should not be processed.

After processing each dataset, output the results of the check (C) commands in the order they appear. Separate the outputs from different datasets by an empty line.

For example, if a check command is executed for a book that has been borrowed, output the user id; otherwise, the output should be available. The problem has been modeled such that it can be expressed in the following mathematical form:

$$\text{result} = \begin{cases}\text{user}, & \text{if book } b \text{ is borrowed by user } u,\\ \text{available}, & \text{otherwise.}\end{cases} $$

inputFormat

The input is provided from standard input. It contains multiple datasets. Each dataset starts with an integer nn (n>0n > 0) indicating the number of commands, followed by nn commands (one per line). Each command is one of the following three types:

• B u b : user u borrows book b. • R u b : user u returns book b (only valid if the book is currently borrowed by u). • C b : check the status of book b.

A line with a single 0 indicates the end of input.

outputFormat

For each dataset, output the results corresponding to each check command (C b) in the order they appear in the input. For each dataset, the outputs are printed on separate lines, and an empty line is printed after processing each dataset.## sample

6
B 1 100
B 2 101
C 100
C 101
R 1 100
C 100
4
B 1 200
C 200
R 1 200
C 200
0
1

2 available

1 available

</p>