#C4345. Simple Banking System Simulation
Simple Banking System Simulation
Simple Banking System Simulation
This problem requires you to simulate a basic banking system that supports operations such as account creation, deposit, withdrawal, balance inquiry, and funds transfer.
You will be given a sequence of commands as input. The commands include:
- CREATE account_number initial_balance: Create an account with an initial balance.
- DEPOSIT account_number amount: Deposit the specified amount into the account.
- WITHDRAW account_number amount: Withdraw the specified amount from the account if sufficient funds exist.
- BALANCE account_number: Output the current balance of the account. If the account does not exist, output
ERROR
. - TRANSFER from_account_number to_account_number amount: Transfer funds between two accounts. The transfer is successful only if both accounts exist and the source account has at least the amount to be transferred. Otherwise, output
ERROR
. - END: Indicates the termination of input.
A transfer operation is valid if \(\text{balance}_{\text{from}} \geq amount\). If the transfer is valid, the system outputs SUCCESS
; otherwise, it outputs ERROR
.
inputFormat
The input consists of multiple lines, each containing one command. The commands are:
CREATE account_number initial_balance
DEPOSIT account_number amount
WITHDRAW account_number amount
BALANCE account_number
TRANSFER from_account_number to_account_number amount
END
(to terminate input)
Read from standard input (stdin).
outputFormat
For each BALANCE
or TRANSFER
command, output the result in the order they appear. For BALANCE
commands output the account balance, and for TRANSFER
commands output either SUCCESS
or ERROR
. Each output should be printed on a new line on standard output (stdout).
CREATE 1 1000
CREATE 2 500
DEPOSIT 1 200
WITHDRAW 2 100
BALANCE 1
TRANSFER 1 2 300
BALANCE 2
END
1200
SUCCESS
700
</p>