#C14026. Bank Account Simulator
Bank Account Simulator
Bank Account Simulator
You are required to simulate a simple bank account that supports three operations: deposit, withdraw, and get_balance. The account starts with an initial balance provided in the input.
Operations are described as follows:
- deposit X: Increase the balance by X if X is a positive number. Print
True
if the deposit is successful, otherwise printFalse
. - withdraw X: Decrease the balance by X if the current balance is at least X and X is positive. Print
True
if the withdrawal is successful, otherwise printFalse
. - get_balance: Print the current balance.
The operations must be processed sequentially. The output for each operation should be printed on a new line.
Note: You need to use stdin for reading input and stdout for printing output. Use LaTeX format for any formulas if necessary. For example, the condition for a successful withdrawal is: $$0 < X \leq \text{balance}.$$
inputFormat
The input consists of multiple lines.
- The first line contains an integer representing the initial balance.
- The second line contains an integer n representing the number of operations.
- The next n lines each describe an operation. Each operation is either:
deposit X
withdraw X
get_balance
outputFormat
For each operation, print the following:
- For
deposit
andwithdraw
operations, printTrue
if the operation succeeds; otherwise, printFalse
. - For
get_balance
, print the current balance as an integer. - Each result should be printed on a new line in the order the operations are provided.
50
4
deposit 100
get_balance
withdraw 80
get_balance
True
150
True
70
</p>