#C8326. Banking System Simulation

    ID: 52296 Type: Default 1000ms 256MiB

Banking System Simulation

Banking System Simulation

This problem requires you to simulate a simple banking system. You are given a sequence of operations which create accounts and perform transactions such as depositing money, withdrawing funds, and transferring money between accounts.

Each operation is given on its own line. The operations are described as follows:

  • CREATE <account> <initial_balance>: Create a new account with the specified initial balance.
  • DEPOSIT <account> <amount>: Deposit the specified amount into the account.
  • WITHDRAW <account> <amount>: Withdraw the specified amount from the account. The withdrawal only occurs if the account has sufficient funds.
  • TRANSFER <source_account> <destination_account> <amount>: Transfer the specified amount from the source account to the destination account. The transfer occurs only if the source account has sufficient funds.

After processing all the operations, you must output the final balance for each account in the order they were created. Note that if an operation cannot be performed (for example, due to insufficient funds), it should be ignored.

Mathematically, if we denote the balance of account A by \(B_A\) then the operations can be formalized as follows:

  • For deposit: \(B_A \leftarrow B_A + a\), where \(a\) is the amount deposited.
  • For withdrawal: \(B_A \leftarrow B_A - a\) if \(B_A \geq a\).
  • For transfer from account \(A\) to \(B\): if \(B_A \geq a\) then \(B_A \leftarrow B_A - a\) and \(B_B \leftarrow B_B + a\).

inputFormat

The input is read from standard input (stdin) and is formatted as follows:

  1. The first line contains an integer \(n\) representing the number of operations.
  2. Each of the next \(n\) lines contains an operation. Each operation is one of the following forms:
  • CREATE account initial_balance
  • DEPOSIT account amount
  • WITHDRAW account amount
  • TRANSFER source_account destination_account amount

All amounts and balances are integers.

outputFormat

After processing all operations, output the final balance for each account in the order they were created. For each account, print a line with the account name followed by a space and the final balance.

## sample
1
CREATE Alice 1000
Alice 1000

</p>