#K64262. Inventory Management System

    ID: 31937 Type: Default 1000ms 256MiB

Inventory Management System

Inventory Management System

You are required to implement an inventory management system that supports the following operations:

  • Add Operation: Add a new item or update an existing item in the inventory. The command format is add item_name weight. If the item already exists, its weight should be updated.
  • Remove Operation: Remove an item from the inventory by its name. The command format is remove item_name. If the item does not exist, output \(ITEM\_NOT\_FOUND\).
  • Print Operation: Print all items in the inventory sorted by their names in ascending order. The command print_inventory will output each item on a new line in the format item_name weight. If the inventory is empty, print an empty line.

All input should be read from stdin and all output should be sent to stdout. Use appropriate data structures to handle the operations efficiently.

Note: For operations that produce output (remove and print_inventory), the output should appear in the order the operation is processed.

inputFormat

The first line contains an integer (n), the number of operations. Each of the next (n) lines contains one operation as described above.

outputFormat

For each operation that produces output (i.e. remove and print_inventory), print the result on a new line. For print_inventory, if the inventory is empty, print an empty line.## sample

3
add sword 10
add shield 15
print_inventory
shield 15

sword 10

</p>