#C14679. Vending Machine Simulation

    ID: 44354 Type: Default 1000ms 256MiB

Vending Machine Simulation

Vending Machine Simulation

This problem requires you to simulate a simple vending machine. The vending machine offers three items:

  • Soda: \( $1.50 \)
  • Chips: \( $1.00 \)
  • Candy: \( $0.65 \)

The machine supports the following operations which are given as commands via standard input:

  • DISPLAY: Display available items with their prices.
  • ACCEPT <amount>: Insert money. Only denominations of $1, $5, or $10 are accepted.
  • SELECT <item>: Attempt to purchase an item. If sufficient funds have been inserted, the item is dispensed and the change is returned. If not, an appropriate message is displayed.

Make sure to use standard I/O for all interactions. The program should read commands from standard input and write responses to standard output.

inputFormat

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

  • DISPLAY
  • ACCEPT <amount> where <amount> is an integer (only 1, 5, or 10 are valid).
  • SELECT <item> where <item> is one of the available items (case-sensitive).

outputFormat

For each command, output the response of the vending machine on its own line. The responses should be exactly as specified:

  • For the DISPLAY command, output the dictionary of items in the format: {'Soda': '$1.50', 'Chips': '$1.00', 'Candy': '$0.65'}.
  • For a valid ACCEPT command, output: Inserted money: $X.XX (with the updated total inserted money).
  • For an invalid denomination, output: Invalid denomination. Please insert $1, $5, or $10.
  • For the SELECT command:
    • If the item exists and sufficient money has been inserted, dispense the item and return any change in the format: Dispensing <item>. Change returned: $Y.YY (after which the inserted money resets to 0).
    • If the item exists but not enough money has been inserted, output: Not enough money. <item> costs $Z.ZZ. Please insert more money.
    • If the item does not exist, output: Invalid selection. Please choose a valid item.
## sample
3
DISPLAY
ACCEPT 5
SELECT Chips
{'Soda': '$1.50', 'Chips': '$1.00', 'Candy': '$0.65'}

Inserted money: $5.00 Dispensing Chips. Change returned: $4.00

</p>