#K92412. Calculate Account Balance
Calculate Account Balance
Calculate Account Balance
You are given a list of transactions. Each transaction consists of three parts: an amount (a positive integer), a type, and a description. The type is either credit or debit. A credit transaction adds the amount to the balance, while a debit transaction subtracts the amount from the balance.
Your task is to calculate the final account balance after processing all the transactions.
Note: The description field is not used in the calculation.
Mathematically, the balance can be expressed as:
[ \text{balance} = \sum_{i=1}^{n} \begin{cases} +,\text{amount}_i & \text{if } \text{type}_i = \texttt{credit}\ -,\text{amount}_i & \text{if } \text{type}_i = \texttt{debit} \end{cases} ]
inputFormat
The input is read from standard input and is formatted as follows:
- The first line contains a single integer n which indicates the number of transactions.
- The next n lines each contain a transaction record with three space-separated values: an integer amount, a string type (either
credit
ordebit
), and a string description (without spaces).
outputFormat
Output the final account balance as an integer to standard output.
## sample4
100 credit Deposit
50 debit Withdrawal
200 credit Refund
20 debit Purchase
230
</p>