#C2380. Warehouse Inventory System
Warehouse Inventory System
Warehouse Inventory System
You are given a series of transactions that simulate operations on a warehouse inventory. Each transaction is represented as a string in the format Operation Item Quantity
, where Operation
is either IN
to add stock or OUT
to remove stock, Item
is the name of the product, and Quantity
is a positive integer.
Your task is to process these transactions and output the final inventory levels for each item. The output must be sorted in alphabetical order of the item names. Each output line should follow the exact format Item: Quantity
.
For example, given the following transactions:
IN Widget 10 OUT Gizmo 5 IN Widget 5 OUT Widget 3 IN Gizmo 15
The expected inventory would be:
Gizmo: 10 Widget: 12
Mathematically, if we denote the inventory of an item I after processing all transactions as \( A(I) \), then:
[ A(I) = \sum_{t \in T_I} \begin{cases} +q, & \text{if the operation is IN} \ -q, & \text{if the operation is OUT} \end{cases} ]
where \( T_I \) is the set of transactions involving item I and \( q \) represents a transaction's quantity.
inputFormat
The input is provided via stdin and begins with an integer n on the first line, representing the number of transactions. The following n lines each contain a transaction in the format:
Operation Item Quantity
There is a single space between Operation, Item, and Quantity.
outputFormat
Output the final inventory of all items via stdout where each line has the format:
Item: Quantity
Items must be printed in alphabetical order. If there are no transactions, output nothing.
## sample5
IN Widget 10
OUT Gizmo 5
IN Widget 5
OUT Widget 3
IN Gizmo 15
Gizmo: 10
Widget: 12
</p>