#K46197. Balance Valid Purchases
Balance Valid Purchases
Balance Valid Purchases
You are given an initial balance and a list of financial transactions. Each transaction is represented by a description and an amount. Only transactions whose description is one of the following valid types:
- Purchase at store A
- Refund from store B
- Purchase at store C
should be used to update the balance. The final balance is computed using the formula:
\( balance = initial\_balance + \sum_{t \in valid} amount_t \)
Write a program that reads the input from stdin in the format specified and outputs the final balance to stdout with two decimal places.
inputFormat
The input is given in stdin and has the following format:
- The first line contains a floating-point number representing the initial balance.
- The second line contains an integer n representing the number of transactions.
- The next n lines each contain one transaction in the format:
description;amount
wheredescription
is a string (without the character ';') andamount
is a floating-point number.
outputFormat
The output should be printed to stdout and consist of a single line containing the final balance formatted to two decimal places.
## sample100.00
3
Purchase at store A;50.75
Refund from store B;-10.25
Purchase at store C;20.00
160.50