#C6921. Simulate Banking System
Simulate Banking System
Simulate Banking System
You are required to simulate a simple banking system. In this system, you can create accounts, deposit money, withdraw money, and query the balance of an account. Each account is uniquely identified by an account number (a positive integer).
The supported operations are:
- CREATE A: Create a new account with account number A and an initial balance of 0.
- DEPOSIT A X: Deposit an amount X into account A. It is guaranteed that X is a non-negative integer.
- WITHDRAW A X: Withdraw an amount X from account A if there are sufficient funds; otherwise, the account balance remains unchanged.
- BALANCE A: Query the current balance of account A. If the account does not exist, output
None
.
Formally, if you denote the current balance of account A as \(B_A\), then after a deposit operation, the new balance becomes \(B_A + X\) and after a successful withdrawal, the new balance becomes \(B_A - X\). If a withdrawal is attempted with \(X > B_A\), no change occurs.
The input will be provided via standard input, and the output should be printed to standard output. Each output should be printed on a separate line corresponding to each BALANCE
query.
inputFormat
The first line of input contains an integer Q (\(1 \le Q \le 10^5\)), representing the number of queries.
The next Q lines each contain a query in one of the following formats:
CREATE A
DEPOSIT A X
WITHDRAW A X
BALANCE A
Here, A and X are integers. All queries are processed in the order given.
outputFormat
For each BALANCE
query, output the current balance of the queried account on a new line. If the account does not exist, output None
(without quotes).
8
CREATE 123
DEPOSIT 123 500
WITHDRAW 123 100
BALANCE 123
CREATE 456
DEPOSIT 456 300
WITHDRAW 456 500
BALANCE 456
400
300
</p>