#C3714. Bank System Simulation

    ID: 47172 Type: Default 1000ms 256MiB

Bank System Simulation

Bank System Simulation

You are required to implement a bank system that supports account creation, deposits, withdrawals, balance checking, and transfers. In this simulation, a series of commands will be provided via standard input to perform operations on bank accounts. When a new account is created, the system should output the account number. Deposits, withdrawals, and transfers update the balance of the account(s). For specific commands:

  • create: Create a new account and print the account number.
  • deposit <account_number> <amount>: Add funds to the account. If the deposit amount is not positive or the account does not exist, output an error message.
  • withdraw <account_number> <amount>: Remove funds from the account. If the withdrawal amount is not positive, output an error message. If the account does not have sufficient funds, print Insufficient funds.
  • balance <account_number>: Output the current balance of the specified account, or an error message if the account is invalid.
  • transfer <from_account> <to_account> <amount>: Move funds from one account to another. Similar to withdrawal, if funds are insufficient print Insufficient funds., and if any account is invalid or the transfer amount is not positive, output the appropriate error message.

Note: For insufficient funds during a withdrawal or transfer, the system should output the message Insufficient funds. on a separate line. All error messages are to be printed exactly as described.

inputFormat

The input is given via standard input (stdin). The first line contains an integer (T) representing the total number of commands. Each of the following (T) lines contains one command. The command formats are as follows:

  • create
  • deposit <account_number> <amount>
  • withdraw <account_number> <amount>
  • balance <account_number>
  • transfer <from_account> <to_account> <amount>

outputFormat

The output is printed to standard output (stdout). For each command, produce the following output:

  • create: Print the newly created account number.
  • balance: Print the current balance of the account.
  • For erroneous operations (such as invalid account numbers, negative amounts, or insufficient funds), print one of the following error messages as appropriate:
    • "Deposit amount must be positive."
    • "Withdrawal amount must be positive."
    • "Transfer amount must be positive."
    • "Invalid account number."
  • If a withdrawal or transfer fails due to insufficient funds, print "Insufficient funds."

Each output should be printed on a new line, in the order the commands that produce output are executed.## sample

6
create
deposit 1 500
balance 1
withdraw 1 100
balance 1
withdraw 1 600
1

500 400 Insufficient funds.

</p>