#C5572. Vending Machine Simulation

    ID: 49236 Type: Default 1000ms 256MiB

Vending Machine Simulation

Vending Machine Simulation

Simulate a vending machine that dispenses snacks based on purchase attempts. The machine sells two types of snacks: chips and candy. The cost for chips is \(2\) dollars and the cost for candy is \(3\) dollars. Each purchase attempt is given in a separate line in the input, with the snack type followed by the number of coins inserted. If the inserted coins are enough (i.e. greater than or equal to the snack's price), one snack is dispensed and the machine collects exactly the price of the snack; otherwise, a message indicating insufficient coins is printed. Processing stops when the input line is exactly "END". At the end, the machine prints a summary of the total snacks dispensed as well as the total money collected.

inputFormat

The input is read from stdin and consists of multiple lines. Each line (except the last one) contains a purchase attempt in the format: "snack coins", where "snack" is either "chips" or "candy", and "coins" is an integer representing the number of 1-dollar coins inserted. The input terminates with a line containing "END".

outputFormat

The output should be written to stdout and consists of several lines. For each purchase attempt (except the termination line), output either:

  • Dispensed 1 chips or Dispensed 1 candy if the coins are sufficient, or
  • Insufficient coins: X where X is the number of coins provided if they are insufficient.

After processing all attempts, output two summary lines:

  • Total snacks dispensed: Chips: A, Candy: B
  • Total money collected: $C
## sample
chips 3
candy 2
chips 1
candy 3
END
Dispensed 1 chips

Insufficient coins: 2 Insufficient coins: 1 Dispensed 1 candy Total snacks dispensed: Chips: 1, Candy: 1 Total money collected: $5

</p>