#C7941. Inventory Management
Inventory Management
Inventory Management
You are given an initial inventory of widgets and a series of operations to perform on the inventory. The operations include:
add
: Add a new widget with a providedid
,description
, andquantity
.remove
: Remove a widget by itsid
.update
: Update the quantity of an existing widget identified by itsid
.summary
: Generate a summary report of the current inventory.
The summary report must contain:
- The total number of widgets.
- The total quantity of all widgets.
- A list of widget descriptions sorted in lexicographical order.
Your task is to process the given operations in order and then output the summary report immediately after the summary
command is encountered (which will always be the last command).
inputFormat
The input is read from standard input (stdin) and has the following format:
- An integer
n
representing the number of initial inventory items. - n lines follow, each containing three values separated by spaces: a string
id
, a stringdescription
(without spaces), and an integerquantity
. - An integer
m
representing the number of operations. - m lines follow, each describing an operation. The operation commands can be one of the following formats:
add id description quantity
remove id
update id quantity
summary
outputFormat
The output is printed to standard output (stdout) and should consist of three lines:
- The first line contains an integer representing the total number of widgets after processing all operations.
- The second line contains an integer representing the total quantity of all widgets.
- The third line contains the widget descriptions sorted in lexicographical order, separated by a single space. If there are no widgets, the third line should be empty.
1
W1 Widget_A 10
2
add W2 Widget_B 5
summary
2
15
Widget_A Widget_B
</p>