#K13651. Inventory Management System

    ID: 23960 Type: Default 1000ms 256MiB

Inventory Management System

Inventory Management System

Develop an inventory management system that supports four commands: ADD, UPDATE, VIEW, and CHECK. The system maintains an inventory of products together with their available quantities. You are required to process a sequence of commands read from standard input and output results to standard output, as described below.

  • ADD <product> <quantity>: Adds a new product with the given quantity if it does not already exist in the inventory.
  • UPDATE <product> <quantity>: Updates the quantity of an existing product (ignore the command if the product does not exist).
  • VIEW: Outputs the current inventory as a dictionary formatted in LaTeX as \( \{\"key1\":value1,\"key2\":value2,\ldots\} \) with the products sorted in lexicographical order (i.e. alphabetically). If the inventory is empty, output \(\{\}\) (an empty dictionary).
  • CHECK <product>: Outputs In Stock if the product exists in the inventory, otherwise outputs Out of Stock.

Only the VIEW and CHECK commands produce output. The ADD and UPDATE commands modify the inventory without generating any output.

inputFormat

The input is read from standard input and begins with an integer (N) that indicates the number of commands. Each of the following (N) lines contains one command in one of the following forms:

  1. ADD
  2. UPDATE
  3. VIEW
  4. CHECK

Commands are processed sequentially.

outputFormat

For every command that produces an output (VIEW or CHECK), print the result on a new line in the order the commands appear. For the VIEW command, output the entire inventory as a dictionary in the exact format ( {"key":value,\ldots} ) with keys sorted lexicographically (alphabetical order). For the CHECK command, print In Stock if the product exists, and Out of Stock otherwise.## sample

6
ADD apple 10
ADD banana 5
UPDATE banana 20
VIEW
CHECK apple
CHECK orange
{"apple":10,"banana":20}

In Stock Out of Stock

</p>