#C10329. Warehouse Inventory Management
Warehouse Inventory Management
Warehouse Inventory Management
You are required to implement a warehouse inventory management system. The system maintains a record of items and their quantities. There are three types of operations:
- Add Item – Initialize a new item in the warehouse with a given quantity. This operation is denoted by the operation code
1
and is always performed on a new item id. - Update Quantity – Update the quantity of an existing item by adding (or subtracting) an amount. This operation is represented by the code
2
. - Get Quantity – Query the current inventory quantity for a given item id. This operation is represented by the code
3
and requires outputting the current quantity.
Implement the system such that it reads input from the standard input (stdin) and writes the results of the queries to standard output (stdout). Use the operations in the order they are provided. The input is guaranteed to be valid, i.e. an add operation will only be performed on a new item id, and update or query operations will always be on items that exist in the system.
Mathematically, if we denote the inventory quantity of an item with id i by \(q_i\), then the operations update \(q_i\) as follows:
\[ q_i \leftarrow \begin{cases} \text{initial quantity} & \text{if adding new item (code 1)}\\ q_i + \text{amount} & \text{if updating quantity (code 2)} \end{cases} \]
inputFormat
The first line contains an integer \(N\) representing the number of operations.
Each of the following \(N\) lines represents an operation in one of the following formats:
1 item_id quantity
: Add a new item with iditem_id
and initial quantityquantity
.2 item_id amount
: Update the quantity of the existing itemitem_id
by addingamount
(which can be negative).3 item_id
: Query the current quantity of the item with iditem_id
.
All tokens are separated by spaces.
outputFormat
For each query operation (operation code 3), output the current quantity of the queried item on a new line. The output should exactly match the expected values in order.
## sample5
1 101 50
1 102 30
2 101 20
2 102 -5
3 101
70