#C3475. Compute Net Balance
Compute Net Balance
Compute Net Balance
You are given a list of financial transactions. Each transaction consists of an integer amount and a type which is either "credit" or "debit". A credit increases the balance by the transaction amount, and a debit decreases the balance by the transaction amount.
Your task is to compute the net balance after applying all transactions in order. Formally, if there are n transactions \( (a_i, t_i) \) where \( t_i \) is either \( \text{credit} \) or \( \text{debit} \), then the net balance is computed as:
\[ B = \sum_{i=1}^{n} \begin{cases} a_i, & \text{if } t_i = \text{credit} \\ -a_i, & \text{if } t_i = \text{debit} \end{cases} \]Make sure your solution processes the input from standard input (stdin) and outputs the result to standard output (stdout).
inputFormat
The input is given in the following format:
- The first line contains a single integer \( n \), representing the number of transactions.
- The following \( n \) lines each contain one transaction. Each transaction is represented by an integer amount followed by a space and then a string which is either "credit" or "debit".
For example:
3 100 credit 50 debit 10 credit
outputFormat
Output a single integer representing the net balance after processing all transactions.
For the above example, the output should be:
60## sample
1
100 credit
100