#C13242. Vending Machine Simulator

    ID: 42759 Type: Default 1000ms 256MiB

Vending Machine Simulator

Vending Machine Simulator

You are tasked with creating a simulator for a vending machine. The machine accepts a certain amount of money, an item price, and an inventory list of items and their quantities. Given a chosen item, the program should simulate the purchase process.

The following rules apply:

  • If the chosen item is not in the inventory, output: Error: Item not available.
  • If the chosen item exists but its quantity is zero, output: Error: Out of stock.
  • If the money inserted is less than the price of the item, output: Error: Insufficient money.
  • Otherwise, the machine dispenses the item, deducts its quantity by one, and returns the change calculated as \(\text{change} = \text{money inserted} - \text{item price}\).

When a purchase is successful, print the change (as a floating-point number), the name of the purchased item, and the updated inventory in the same order as input. The updated inventory should be printed as space-separated item:quantity pairs.

inputFormat

The input is given in multiple lines from the standard input (stdin):

  1. The first line contains a floating-point number representing the money inserted.
  2. The second line contains a floating-point number representing the price of the item.
  3. The third line contains an integer N specifying the number of items in the inventory.
  4. The next N lines each contain a string and an integer, representing an item name and its quantity, separated by a space.
  5. The last line contains the name of the item the user wants to purchase.

outputFormat

If an error occurs (item not available, out of stock, or insufficient money), output the corresponding error message on a single line.

Otherwise, output the following to stdout:

  1. The first line: the change (as a floating-point number with one decimal place).
  2. The second line: the name of the purchased item.
  3. The third line: the updated inventory printed as space-separated item:quantity pairs in the same order as given in the input.
## sample
2.0
1.5
2
chips 10
soda 5
chips
0.5

chips chips:9 soda:5

</p>