#C358. Library Inventory Management
Library Inventory Management
Library Inventory Management
Implement a library inventory system. You are given three lines of input from standard input. The first line is a string indicating the operation: add
, update
, or remove
. The second line is a JSON object representing a book with three fields: isbn
(a string), title
(a string), and quantity
(an integer). The third line is a JSON object representing the current inventory, where each key is an ISBN and its value is an object with fields title
and quantity
.
For the add operation, if the ISBN already exists in the inventory, increase its quantity. Otherwise, add the new book to the inventory.
For the update operation, if the ISBN exists in the inventory, update its quantity to the new value; if it does not exist, output an error message: ISBN ISBN not found in inventory.
For the remove operation, if the ISBN exists and there is sufficient quantity (i.e. inventory quantity (q\ge \text{remove amount})), decrease the quantity (and remove the book from the inventory if the quantity reaches zero). If the ISBN does not exist or the quantity is insufficient, output the appropriate error message.
Book information is considered invalid if the isbn
or title
is an empty string or if quantity < 0
. In that case, output Invalid book information provided.
Note: The mathematical constraint is given by the inequality: [ q \geq 0 ] where (q) is the quantity of a book.
inputFormat
The input consists of three lines read from standard input (stdin):
- A string representing the operation ("add", "update", or "remove").
- A JSON object representing the book information with keys: "isbn" (string), "title" (string), and "quantity" (integer).
- A JSON object representing the current inventory, where each key is an ISBN and its corresponding value is an object containing "title" and "quantity".
outputFormat
Output the updated inventory as a JSON object to standard output (stdout). If an error occurs because of an invalid operation, invalid book information, or insufficient quantity, output the corresponding error message string.## sample
add
{"isbn": "978-0-13-468599-1", "title": "Effective Python", "quantity": 10}
{}
{"978-0-13-468599-1": {"title": "Effective Python", "quantity": 10}}