#K68832. Simulated Bank Transaction System
Simulated Bank Transaction System
Simulated Bank Transaction System
You are provided with a simulation of a bank transaction system. The system maintains a list of users and their account balances. Initially, there are n users. For each user, you are given their name and an initial balance.
After initialization, a series of commands are provided. The commands can be one of the following:
DEPOSIT user amount
: Increase the specified user's balance by amount.WITHDRAW user amount
: Decrease the specified user's balance by amount only if the current balance is at least amount.BALANCE user
: Output the current balance of the specified user. If the user does not exist, output 0.
For any deposit or withdrawal, the balance is updated according to the following formulas:
- After deposit: \(B_{new} = B_{old} + x\)
- After withdrawal (if permitted): \(B_{new} = B_{old} - x\)
Print the results of each BALANCE
command on a separate line in the order of appearance.
inputFormat
The input is read from standard input (stdin). The first line contains an integer n indicating the number of accounts. The next n lines each contain a user's name and their initial balance separated by a space.
The remaining lines contain commands. Each command is either:
DEPOSIT user amount
WITHDRAW user amount
BALANCE user
outputFormat
For each BALANCE
command, output a single line with the current balance of the specified user (or 0 if the user does not exist). The outputs should be in the order the BALANCE
commands appear in the input.
3
alice 100
bob 200
charlie 150
DEPOSIT alice 50
WITHDRAW bob 100
BALANCE alice
BALANCE bob
WITHDRAW alice 200
BALANCE alice
BALANCE charlie
DEPOSIT charlie 70
BALANCE charlie
WITHDRAW bob 150
BALANCE bob
150
100
150
150
220
100
</p>