#K49742. Warehouse Inventory Management
Warehouse Inventory Management
Warehouse Inventory Management
You are given an initial warehouse inventory and a series of operations. The inventory is represented by a set of categories each with an associated count. The operations are of three types:
- add: Increase the inventory count for a given category by a specified amount. If the category does not exist, add it with the given count.
- update: Set the inventory count of a given category to the specified amount (regardless of whether it already exists).
- retrieve: Output the current count for the given category. If the category does not exist, output 0 (i.e. \(0\)).
Process the operations in the order they appear. For each retrieve operation, output the current count on a separate line.
Note: If a category is not present in the inventory, its count is considered \(0\).
inputFormat
The input is read from standard input (stdin) and has the following format:
- An integer
n
representing the number of inventory items. n
lines follow, each containing a category name (a string) and an integer representing the count.- An integer
m
representing the number of operations. m
lines follow, each describing an operation in one of the following formats:add <category> <value>
update <category> <value>
retrieve <category>
outputFormat
For each retrieve
operation, output the current count for the specified category on a new line.
1
electronics 50
1
retrieve electronics
50
</p>