#K68822. Taco Store Inventory Management Challenge

    ID: 32950 Type: Default 1000ms 256MiB

Taco Store Inventory Management Challenge

Taco Store Inventory Management Challenge

This problem simulates a store inventory management system with shopping cart functionality. You will be given a series of operations to manage the store. The available operations are described below:

  1. Add product to store: Input in the format: 1 name price quantity. This operation adds a product with the given name, price, and quantity to the store inventory.
  2. Add product to cart: Input in the format: 2 name quantity. This operation adds the specified quantity of the product to the shopping cart if the store has enough available stock.
  3. Remove product from cart: Input in the format: 3 name quantity. This operation removes the specified quantity of the product from the cart and restores it to the store inventory. If the removal quantity equals the quantity in the cart, the product is removed from the cart.
  4. Checkout: Input in the format: 4. When this operation is executed, the system calculates the total cost of items in the cart and outputs the total cost along with the names of the purchased products, then terminates processing.

Note: The product names are unique. Operations are processed in order and the checkout operation will always be the last operation processed.

inputFormat

The input begins with a single integer n (n > 0), representing the number of operations. Each of the following n lines contains an operation in one of the following formats:

1 name price quantity 2 name quantity 3 name quantity 4

Operations: • Operation 1: Add a product to the store inventory. • Operation 2: Add a product to the shopping cart if available in inventory. • Operation 3: Remove a product from the cart and restore it to inventory. • Operation 4: Checkout - calculate the total cost and list purchased items, then exit.

outputFormat

When the checkout operation (command 4) is executed, output two lines:

• The first line contains the total cost of the purchased items, formatted to two decimal places. • The second line contains the names of the purchased products separated by a single space. If the cart is empty, this line should be empty.## sample

3
1 Tablet 299.99 15
2 Tablet 5
4
1499.95

Tablet

</p>