#C10217. Online Shopping Cart System

    ID: 39398 Type: Default 1000ms 256MiB

Online Shopping Cart System

Online Shopping Cart System

You are required to implement an online shopping cart system. The system stores items where each item has a name, price, and quantity. The shopping cart should support the following operations:

  • ADD: Add an item with given name, price, and quantity. If the item already exists, simply increase its quantity.
  • UPDATE: Update the quantity of an existing item (if the item does not exist, do nothing).
  • REMOVE: Remove an item from the cart (if the item does not exist, do nothing).
  • TOTAL: Calculate and output the total cost of the items in the cart. The cost of each item is given by \(price \times quantity\).

The operations will be provided via standard input; for every TOTAL command, you should output the current total cost to standard output.

inputFormat

The first line of input contains an integer \(n\) representing the number of operations. The following \(n\) lines each contain a command in one of the following formats:

  • ADD name price quantity: Add the specified item. If the item already exists, add the given quantity to it.
  • UPDATE name quantity: Update the quantity of the specified item.
  • REMOVE name: Remove the specified item from the cart.
  • TOTAL: Output the total cost of items currently in the cart.

outputFormat

For each TOTAL command encountered in the input, output a single line to standard output containing the total cost of the items in the cart. If the total cost is an integer, output it without any decimal point; otherwise, output the floating point value.

## sample
5
ADD apple 1.0 2
ADD banana 0.5 5
TOTAL
UPDATE apple 5
TOTAL
4.5

7.5

</p>