#K53552. Library Inventory Management

    ID: 29556 Type: Default 1000ms 256MiB

Library Inventory Management

Library Inventory Management

You are in charge of a library inventory system. The library processes a series of transactions that either add a book to the inventory or allow a user to borrow a book. Your task is to simulate this system.

There are two types of transactions:

  • ADD <book_name>: Add a copy of the book named book_name to the library. If the book is already present, simply increase its count.
  • BORROW <book_name>: Borrow a copy of the book named book_name. If the book exists in the inventory and at least one copy is available, print YES and decrease its count by one. Otherwise, print NO.

The transaction list is terminated by the command END (which is not processed as a transaction). After processing all transactions, output the responses to all BORROW commands in the order they appear, followed by the final inventory status for each book. The final inventory status should be printed in the order in which the books were first added, in the format:

\(\texttt{book\_name: count}\)

Note: All formulas, if any, must be written in LaTeX format.

inputFormat

The input is given via standard input and consists of multiple lines. Each line represents a transaction in one of the following formats:

  • ADD <book_name>
  • BORROW <book_name>

The sequence ends with a line containing the word END, which should not be processed.

outputFormat

For each BORROW transaction, output a single line containing either YES if the borrowing was successful, or NO otherwise. After processing all transactions, output the final inventory. For each book that was ever added, output a line in the format:
book_name: count

The order of the inventory output should match the order in which the books were first added.

## sample
ADD HarryPotter1
ADD HarryPotter2
ADD HarryPotter1
BORROW HarryPotter1
BORROW HarryPotter2
BORROW HarryPotter3
END
YES

YES NO HarryPotter1: 1 HarryPotter2: 0

</p>