#C13225. Online Store Checkout Simulation

    ID: 42740 Type: Default 1000ms 256MiB

Online Store Checkout Simulation

Online Store Checkout Simulation

You are given a list of items in an online store and an optional discount code. Each item has an id, name, quantity, and price. Your task is to simulate the checkout process by calculating the total cost, applying a discount if applicable, and generating a detailed receipt. If the discount code is 'SAVE10' and the total cost is greater than 50, a discount of ( total_cost \times 0.10 ) is applied. The receipt must include an array of items (with each item showing its id, name, quantity, price, and the computed total cost per item), the overall total cost, the discount code provided, the discount amount, and the final cost after discount.

inputFormat

The input is read from standard input (stdin). The first line contains an integer n representing the number of items. The next n lines each contain four space-separated values: id (integer), name (string without spaces), quantity (integer or float), and price (integer or float). The last line contains a discount code string. If no discount code is provided, the string will be 'NONE'.

outputFormat

Print to standard output (stdout) a JSON string representing a receipt. The JSON object must contain the following keys:

  • items: an array where each element is an object with keys id, name, quantity, price, and total (quantity multiplied by price for that item).
  • total_cost: the sum of all item totals.
  • discount_code: the provided discount code, or 'NONE'.
  • discount: if the discount code is 'SAVE10' and total_cost > 50, then discount = total_cost * 0.10 (i.e., ( total_cost \times 0.10 )); otherwise, 0.
  • final_cost: total_cost minus discount.## sample
1
1 item1 2 20
NONE
{"items": [{"id": 1, "name": "item1", "quantity": 2, "price": 20, "total": 40}], "total_cost": 40, "discount_code": "NONE", "discount": 0.0, "final_cost": 40.0}