#K65977. Inventory Management System
Inventory Management System
Inventory Management System
In this problem, you are to implement an inventory management system. Your system will process a sequence of operations provided line by line. The types of operations are:
- ADD item_name quantity: Add a new item with the specified quantity to the inventory. If the item already exists, output "Item already exists"; otherwise, add the item and output "OK".
- UPDATE item_name quantity: Update the quantity of an existing item in the inventory. If the item does not exist, output "Item does not exist"; otherwise, update the quantity and output "OK".
- ORDER item_name quantity: Process an order by decrementing the quantity of the specified item. If the item does not exist or if there is insufficient stock, output "Order cannot be processed"; otherwise, decrease the stock and output "OK".
The input is read from standard input and is terminated by a line containing EOF (which should not be processed). Your task is to process all operations in order and output the result of each on a new line to standard output.
Note: All the numerical values in the operations are positive integers.
inputFormat
The input consists of several lines. Each line, except the final one, contains an operation in one of the following formats:
ADD item_name quantity
UPDATE item_name quantity
ORDER item_name quantity
The final line will be the string EOF
, which signals the end of input and should not be processed.
outputFormat
The output should be printed to standard output. For every processed operation, print the result on a new line. The output for each operation is one of:
OK
Item already exists
Item does not exist
Order cannot be processed
ADD burger 10
ADD fries 5
ORDER burger 3
ORDER fries 6
UPDATE fries 10
ORDER fries 6
ADD drink 8
ORDER drink 2
ADD burger 5
UPDATE salad 4
ORDER salad 1
EOF
OK
OK
OK
Order cannot be processed
OK
OK
OK
OK
Item already exists
Item does not exist
Order cannot be processed
</p>