#C13879. Inventory Management System

    ID: 43465 Type: Default 1000ms 256MiB

Inventory Management System

Inventory Management System

You are required to implement an inventory management system that supports basic operations such as adding an item, updating its quantity, removing an item, checking the quantity of a given item, and printing the current inventory status. The operations are defined as follows:

  • add <item> <quantity>: Adds a new item to the inventory with the specified quantity. If the item already exists, its quantity is increased by the specified amount.
  • update <item> <quantity>: Sets the quantity of an existing item to the given amount. If the item does not exist, output an error message: Item not found.
  • remove <item>: Removes an item from the inventory. If the item does not exist, output an error message: Item not found.
  • check <item>: Prints the current quantity of the specified item. If the item does not exist, output an error message: Item not found.
  • status: Prints a comma separated list of items and their quantities in the format item: quantity. If the inventory is empty, print an empty line.

All error messages and outputs must be printed to stdout. The operations are input via standard input (stdin). Note: For any quantity modifications, consider the update formula as follows: \( new \ quantity = old \ quantity + quantity \) for the add operation, and a direct update for the update operation.

inputFormat

The input begins with a single integer T indicating the number of commands. Each of the next T lines contains a command. The commands are one of the following formats:

  1. add
  2. update
  3. remove
  4. check
  5. status

All commands and their arguments are space-separated. The item name is a string without spaces and quantity is an integer.

outputFormat

For commands that require output (i.e. check, status, and error messages from update or remove operations when the item does not exist), print the result to stdout. For the 'check' command, if the item exists, print its quantity; otherwise, print 'Item not found'. For the 'status' command, print a comma separated list of all items in the format 'item: quantity'. If there are no items, print an empty line.## sample

6
add apple 10
add banana 5
update banana 10
remove orange
check banana
status
Item not found

10 apple: 10, banana: 10

</p>