#K63997. Warehouse Inventory Operations
Warehouse Inventory Operations
Warehouse Inventory Operations
In this problem, you are tasked with managing a warehouse's inventory through a series of operations. The warehouse supports three types of operations:
- ADD sku quantity: Add a new product with the given SKU and initial quantity. If the SKU already exists, this operation will override its current quantity.
- UPDATE sku quantity: Update the quantity of an existing product by adding the given quantity (which can be negative). If the SKU does not exist, create it with the given quantity.
- QUERY sku: Query the current quantity of the product with the given SKU. If the product does not exist, return 0.
You need to implement the warehouse system so that it processes these commands. The input will be provided via standard input. The first line contains an integer N, the number of operations. The next N lines each contain a command as described above. For each QUERY operation, output the result on a separate line.
The operations should be processed in the order they are given. All calculations are done using standard integer arithmetic. Note that using negative quantities is allowed and might result in negative inventory values.
inputFormat
The first line of input contains a single integer N, representing the number of operations. Each of the next N lines contains a string representing an operation. The operation is one of the following forms:
- ADD sku quantity
- UPDATE sku quantity
- QUERY sku
Here, sku and quantity are integers.
outputFormat
For each QUERY operation in the order they appear, output the corresponding inventory quantity on a new line.## sample
6
ADD 1001 50
ADD 1002 30
UPDATE 1001 -10
QUERY 1001
QUERY 1002
QUERY 1003
40
30
0
</p>