#K59177. Bookstore Inventory Manager

    ID: 30807 Type: Default 1000ms 256MiB

Bookstore Inventory Manager

Bookstore Inventory Manager

In this problem, you are required to implement an inventory manager for a bookstore. The manager should support four types of operations: \(\text{add_book}\), \(\text{update_book}\), \(\text{remove_book}\) and \(\text{list_books}\). Each book is identified by a unique id and has associated attributes: title, author, price, and quantity. The operations must be processed in the order they appear in the input.

For an \(\text{add_book}\) operation, if the book with the given id does not exist, add it to the inventory. Duplicate additions (i.e. when a book with the same id is already present) must be ignored. The \(\text{update_book}\) operation updates the details of an existing book; if the book does not exist, ignore the operation. The \(\text{remove_book}\) operation deletes a book if it exists. The \(\text{list_books}\) operation prints the details of all books in the inventory in the order of insertion. If the inventory is empty, output "No books available".

inputFormat

The input is given from stdin as a JSON array of operations. Each operation is a JSON object with a mandatory key "operation" and other keys depending on the type of operation. For example, an add_book operation will include keys "id", "title", "author", "price" and "quantity".

outputFormat

The output should be written to stdout. For each \(\text{list_books}\) operation encountered while processing the operations, print the details of all books in the inventory, each on a new line, in the format:

id: <id>, Title: <title>, Author: <author>, Price: <price>, Quantity: <quantity>

If the inventory is empty when a \(\text{list_books}\) operation is processed, output:

No books available

## sample
[{"operation": "add_book", "id": "1", "title": "The Catcher in the Rye", "author": "J.D. Salinger", "price": 9.99, "quantity": 5}, {"operation": "add_book", "id": "2", "title": "To Kill a Mockingbird", "author": "Harper Lee", "price": 12.99, "quantity": 3}, {"operation": "list_books"}, {"operation": "update_book", "id": "1", "title": "The Catcher in the Rye", "author": "J.D. Salinger", "price": 7.99, "quantity": 10}, {"operation": "remove_book", "id": "2"}, {"operation": "list_books"}]
id: 1, Title: The Catcher in the Rye, Author: J.D. Salinger, Price: 9.99, Quantity: 5

id: 2, Title: To Kill a Mockingbird, Author: Harper Lee, Price: 12.99, Quantity: 3 id: 1, Title: The Catcher in the Rye, Author: J.D. Salinger, Price: 7.99, Quantity: 10

</p>