#C175. Basic Bank Account Simulation
Basic Bank Account Simulation
Basic Bank Account Simulation
You are required to simulate a basic bank account which supports deposits, withdrawals, balance checking, and printing the transaction statement. The account is initialized with a starting balance. For deposits, the balance increases by the given amount; for withdrawals, the balance decreases if there is sufficient funds, otherwise an error message "Insufficient balance" is output and no transaction is recorded. The statement prints all transactions (both deposits and withdrawals) in the order in which they occurred in a JSON array format.
inputFormat
The input is read from standard input (stdin) with the following format:
Line 1: An integer representing the starting balance.
Line 2: An integer Q representing the number of operations.
Next Q Lines: Each line contains an operation which can be one of the following:
• deposit x: Deposit an amount x.
• withdraw x: Withdraw an amount x. If the balance is insufficient, output "Insufficient balance" and ignore the operation.
• get_balance: Output the current balance.
• get_statement: Output a JSON array of all transactions. Each transaction is an object with keys "type" and "amount". If there are no transactions, output an empty array [].
outputFormat
For each operation, output the result on a new line to standard output (stdout) as described below:
• For a deposit operation, output the updated balance after the deposit.
• For a withdraw operation, output the updated balance if the withdrawal is successful; otherwise, output "Insufficient balance".
• For a get_balance operation, output the current balance.
• For a get_statement operation, output the list of transactions as a JSON array (e.g., [{"type": "deposit", "amount": 300}, {"type": "withdrawal", "amount": 200}]).
1000
4
get_balance
deposit 500
get_balance
withdraw 200
1000
1500
1500
1300
</p>