#C8028. Simulate Banking Transactions
Simulate Banking Transactions
Simulate Banking Transactions
You are given a series of banking transactions. Each transaction is represented by a string in which the first character indicates the type of transaction: 'D' for deposit and 'W' for withdrawal. The rest of the string is a positive integer representing the amount. Starting with an initial balance of 0, process the transactions one by one. If the transaction is a deposit, add the amount to the balance; if it is a withdrawal, subtract the amount. If at any point the balance becomes negative (i.e. ), the operation is considered invalid and should immediately output "Insufficient funds". Otherwise, after processing all transactions, output the final balance.
Input Format: The first line contains an integer , the number of transactions. The next lines each contain one transaction string.
Output Format: Output the final balance as an integer if all transactions are processed successfully. If any transaction causes the balance to go below zero, output "Insufficient funds".
inputFormat
The first line contains an integer representing the number of transactions. The following lines each contain a transaction string (e.g., D200 or W100).
outputFormat
Print the final balance as an integer on stdout if all transactions are valid. If any transaction results in a negative balance, print "Insufficient funds" instead.## sample
3
D200
D300
D500
1000
</p>