#C13059. Inventory Management System
Inventory Management System
Inventory Management System
Implement a simple inventory management system that supports a series of operations to manage items in a store. The system maintains an inventory as a dictionary mapping an item identifier to its quantity. You need to implement the following operations:
- ADD identifier quantity: Inserts a new item with the given identifier and quantity. If the item already exists or the quantity is negative, output the appropriate error message.
- UPDATE identifier quantity: Updates the quantity of an existing item. If the item does not exist or the quantity is negative, output the appropriate error message.
- REMOVE identifier: Removes an item by its identifier. If the item does not exist, output the appropriate error message.
- DISPLAY: Prints the current inventory in a dictionary format (e.g., {'item1': 10, 'item2': 5}).
For commands that produce an error (e.g., adding an existing item, updating a non-existent item, negative quantity), print the error message immediately. The error messages are exactly:
- For ADD when the item exists: "Item with identifier 'identifier' already exists."
- For UPDATE or ADD when the quantity is negative: "Quantity must be non-negative."
- For UPDATE or REMOVE when the item does not exist: "Item with identifier 'identifier' does not exist."
inputFormat
The first line of input contains an integer n representing the number of operations. Each of the following n lines contains one command. The commands can be one of the following:
- ADD identifier quantity
- UPDATE identifier quantity
- REMOVE identifier
- DISPLAY
Read the commands from standard input and process them sequentially.
outputFormat
For each command, if an error occurs, output the corresponding error message on a new line. For the DISPLAY command, output the current inventory in a dictionary format exactly as shown, with keys enclosed in single quotes and items separated by commas. The output should be printed to standard output.
## sample4
ADD item1 10
DISPLAY
ADD item1 5
DISPLAY
{'item1': 10}
Item with identifier 'item1' already exists.
{'item1': 10}
</p>