#K6461. Process Bank Transactions
Process Bank Transactions
Process Bank Transactions
You are given a series of bank transaction logs. Each transaction log contains a timestamp, a username, an amount, and a transaction type (either deposit
or withdraw
). Your task is to calculate the final balance for each user.
For each user, the final balance is computed as follows:
\(\text{balance} = \sum \text{deposits} - \sum \text{withdrawals}\)
The output should list each user and their final balance on a separate line, with users sorted in lexicographical order by their username.
inputFormat
The input is given via standard input (stdin). The first line contains an integer t which represents the number of transactions. The following t lines each contain a transaction record in the format:
timestamp username amount transaction_type
Here, timestamp
is a string representing the time (which can be ignored during processing), username
is the user's identifier, amount
is a positive integer, and transaction_type
is either deposit
or withdraw
.
outputFormat
Output the final balance for each user on separate lines via standard output (stdout). Each line should be in the format:
username balance
Users must be listed in lexicographical order of their usernames.
## sample6
09:00 userA 1000 deposit
09:30 userB 1500 deposit
10:00 userA 200 withdraw
10:15 userB 500 deposit
11:00 userC 700 deposit
11:30 userC 300 withdraw
userA 800
userB 2000
userC 400
</p>