#C69. Library Book Management

    ID: 50710 Type: Default 1000ms 256MiB

Library Book Management

Library Book Management

You are given a series of library transactions. There are two types of transactions:

  • Borrowing: Represented by the number 1. When a borrowing operation occurs, if there is any donated book available, the last donated book is borrowed (i.e., removed from the collection). Otherwise, the result is No Book.
  • Donation: Represented by a transaction starting with 2 followed by a book name. For example, 2 BookName indicates that BookName is donated to the library. Donated books are stored in a stack, and the most recently donated book is borrowed first.

The process can be modeled by the following stack operation: For each transaction, if the transaction is 1, output the top of the stack if it exists, otherwise output No Book; if the transaction starts with 2, push the book name onto the stack.

Formally, if we denote the stack by \(S\), then the operations are:

  • For a borrowing operation (\(\text{transaction} = 1\)): \[ \text{result} = \begin{cases} S.pop() & \text{if } S \neq \emptyset \\ \text{\text{No Book}} & \text{if } S = \emptyset \end{cases} \]
  • For a donation operation (\(\text{transaction} = 2\, BookName\)): \(S.push(\text{BookName})\).

Your task is to simulate these transactions and output the results of all borrowing operations in the order they occur.

inputFormat

The input is read from stdin and consists of:

  1. An integer n on the first line, which indicates the number of transactions.
  2. n lines follow, each representing a transaction. Each transaction is either:
    • 1 (indicating a borrowing operation), or
    • 2 BookName (indicating a donation operation, where BookName is a string without spaces or may contain spaces).

outputFormat

For each borrowing operation (1), output the result on a new line:

  • If a book is available (i.e. the stack is not empty), output the name of the borrowed book.
  • If no book is available, output No Book.

The output is written to stdout.

## sample
7
1
2 HarryPotter
2 ToKillAMockingBird
1
1
2 GreatGatsby
1
No Book

ToKillAMockingBird HarryPotter GreatGatsby

</p>