#C13323. Inventory Manager System

    ID: 42849 Type: Default 1000ms 256MiB

Inventory Manager System

Inventory Manager System

In this problem, you are required to simulate an inventory management system for a store. Initially, the inventory is empty. You will be given a sequence of operations to add items to the inventory, remove items, and check the quantity of an item. For the 'add' and 'remove' operations, the quantity is a positive integer. Removing an amount greater than the available quantity sets the quantity to 0. When querying an item that is not in the inventory using the 'check' operation, output the string "Item not in inventory".

Operations:

  • add: Increase the quantity of the given item by the specified amount. If the item does not exist, add it with that quantity.
  • remove: Decrease the quantity of the given item by the specified amount. If the operation would result in a negative quantity, set it to 0. If the item does not exist, add it with a quantity of 0.
  • check: Output the current quantity of the given item. If the item does not exist, output "Item not in inventory".

All operations must be processed sequentially in the order they are given.

inputFormat

The first line contains a single integer nn, the number of operations. Each of the next nn lines describes an operation in one of the following formats:

  1. For the 'add' and 'remove' operations: action item quantity, where action is either 'add' or 'remove', item is a string without spaces, and quantity is a positive integer.
  2. For the 'check' operation: action item, where action is 'check' and item is the item name.

outputFormat

For each 'check' operation, output the current quantity of the item if it exists, or the string "Item not in inventory" if it does not. Each output should be printed on a separate line.## sample

7
add apple 10
add apple 5
check apple
remove apple 3
check apple
remove banana 5
check banana
15

12 0

</p>