#K34222. Taco Transactions: Process Bank Operations
Taco Transactions: Process Bank Operations
Taco Transactions: Process Bank Operations
You are given a series of bank transactions for various customers. Each transaction is in one of the following formats:
- DEPOSIT customerID amount: Deposit an amount a to the account of customer customerID.
- WITHDRAW customerID amount: Withdraw an amount a from the account of customer customerID if sufficient funds are available.
- TRANSFER fromCustomerID toCustomerID amount: Transfer an amount a from customer fromCustomerID to customer toCustomerID if the sender has sufficient funds.
All customers start with an initial balance of 0. For each test case, output the final balances of all customers sorted in ascending order of their customer IDs.
If a withdrawal or transfer operation is attempted without sufficient balance, the operation is ignored.
All formulas and conditions can be expressed using LaTeX where needed, for example: A transaction is executed only if $$balance \geq amount.$$
inputFormat
The input starts with an integer T representing the number of test cases. For each test case:
- The first line contains an integer n, the number of operations.
- The next n lines each contain a transaction in one of the three formats:
- DEPOSIT customerID amount
- WITHDRAW customerID amount
- TRANSFER fromCustomerID toCustomerID amount
outputFormat
For each test case, output the final balances of all customers in ascending order of customer ID. Print each record on a new line in the format:
customerID balance## sample
2
3
DEPOSIT 1 100
WITHDRAW 1 50
TRANSFER 1 2 20
2
DEPOSIT 3 500
WITHDRAW 4 200
1 30
2 20
3 500
4 0
</p>