#C9075. Library Command Processor
Library Command Processor
Library Command Processor
You are given a series of commands to manage a library’s inventory. The commands allow you to add books, borrow books, return books, and count the available books in the library. The commands are as follows:
- ADD x: Add a book with an identifier \(x\) to the library. If the book is already in the library, ignore the command.
- BORROW x: Borrow the book with identifier \(x\) if it exists and is currently available. If the book is not available or does not exist, ignore the command.
- RETURN x: Return the book with identifier \(x\) if it was previously borrowed. If the book is not borrowed (or doesn’t exist), ignore the command.
- COUNT: Count the number of available books in the library and output this number.
Process the commands in the given order. Each time a COUNT
command is encountered, print the count of available books on a new line.
Note: All formulas (if any) are represented in \( \LaTeX \) format.
inputFormat
The input consists of multiple lines. The first line contains an integer \(n\), representing the number of commands. Each of the following \(n\) lines contains one command from the set {ADD, BORROW, RETURN, COUNT} as described.
outputFormat
For each COUNT
command in the input, output a single line with the number of available books in the library at that moment.
8
ADD 1001
ADD 1002
BORROW 1001
COUNT
RETURN 1001
BORROW 1003
COUNT
RETURN 1002
1
2
</p>