#K55482. Inventory Management System

    ID: 29985 Type: Default 1000ms 256MiB

Inventory Management System

Inventory Management System

This problem requires you to implement an inventory management system that supports a range of commands. The commands include:

  • ADD <product_code> <quantity>: Adds the specified quantity to the product with the given product code.
  • REMOVE <product_code> <quantity>: Removes the specified quantity from the product if sufficient stock is available. If the available quantity is less than the quantity to remove, no change is made.
  • REPORT <product_code>: Outputs the current quantity of the product. If the product does not exist, output 0.
  • STOCK: Outputs the total number of distinct products present in the inventory.
  • ALLSTOCK: Outputs a list of all products and their quantities in ascending order by product code. Each product is displayed in the format product_code quantity.

All commands are processed sequentially. The solution must read input from stdin and produce the expected outputs to stdout.

inputFormat

The first line of input is an integer N, representing the number of commands. Each of the next N lines contains one command. The commands can be in any of the following forms:

  • ADD product_code quantity
  • REMOVE product_code quantity
  • REPORT product_code
  • STOCK
  • ALLSTOCK

outputFormat

For each command that produces output (REPORT, STOCK, and ALLSTOCK), print the result on a new line. In the case of ALLSTOCK, output each product and its quantity on a new line in the format "product_code quantity".

## sample
4
ADD 101 50
ADD 102 30
REPORT 101
REPORT 102
50

30

</p>