#C3599. Account Balance Calculation
Account Balance Calculation
Account Balance Calculation
Given a series of banking transactions, compute the final account balance. Each transaction is presented in the format D amount
for a deposit and W amount
for a withdrawal.
The account balance starts at 0. For each transaction, update the balance accordingly. Deposits add to the balance and withdrawals subtract from the balance.
The operation can be mathematically represented as: \[ B = \sum_{i=1}^{N} v_i \] where \(v_i\) is a positive value if the transaction is a deposit and negative if it is a withdrawal.
inputFormat
The first line contains an integer N
representing the number of transactions.
Each of the next N
lines contains a transaction in the format D amount
or W amount
, where D
denotes a deposit and W
denotes a withdrawal. The amount
is an integer.
outputFormat
Output a single integer which is the final account balance after processing all transactions.
## sample4
D 300
D 200
D 100
D 50
650