#C12775. Inventory Management System
Inventory Management System
Inventory Management System
This problem simulates an inventory management system for a store. You will be given a series of commands to either add an item with its quantity or to query the current quantity of an item. The commands you need to implement are:
- ADD <item_name> <quantity>: Increase the inventory for the given item by the specified quantity.
- QUERY <item_name>: Output the current quantity of the given item. If the item does not exist, output 0.
The problem can be mathematically modeled as follows: If \( I(x) \) is the inventory for item \( x \), then for a command ADD x q we update \( I(x) = I(x) + q \), and for a command QUERY x we output \( I(x) \) (with \( I(x) = 0 \) if not previously added).
inputFormat
The input is provided via standard input (stdin). The first line contains an integer ( n ) denoting the number of commands. This is followed by ( n ) lines, each containing one command. Each command is formatted as either "ADD <item_name> " or "QUERY <item_name>".
outputFormat
The output should be printed to standard output (stdout). For each "QUERY" command in the order of appearance, print the current quantity of the item on a new line.## sample
6
ADD apple 10
QUERY apple
ADD banana 5
QUERY banana
ADD apple 5
QUERY apple
10
5
15
</p>