#C13756. Basic Inventory Management
Basic Inventory Management
Basic Inventory Management
In this problem, you need to implement a basic inventory management system to manage an online store's inventory. The system supports the following commands:
- add <item> <quantity>: Adds an item with the specified quantity. If the item already exists, its quantity will be increased by the given amount.
- update <item> <quantity>: Updates the quantity of an existing item. If the item does not exist, output an error message: \(\texttt{Item \{item\} not found in inventory}\).
- get: Outputs the current inventory as a JSON object with keys sorted lexicographically.
- search <item>: Searches for an item by name. If the item exists, output its quantity; otherwise, output \(\texttt{Item \{item\} not found in inventory}\).
inputFormat
The input begins with an integer (T) representing the number of commands. Each of the following (T) lines contains one command. For commands that require an item name with spaces, the name will be enclosed in double quotes. Valid commands are: add
, update
, get
, and search
.
outputFormat
For each command that produces output (get
and search
commands, as well as error messages from update
when the item is not found), print the result on a separate line. For the get
command, output the inventory as a JSON object with keys sorted in lexicographical order.## sample
6
add Laptop 10
get
search Laptop
search Smartphone
update Laptop 5
get
{"Laptop": 10}
10
Item Smartphone not found in inventory
{"Laptop": 5}
</p>