ATM Transactions
InterviewTime limit1sMemory limit128 MB
Process ATM withdrawal or deposit lines, updating balance but rejecting withdrawals that push it below -200, until a sentinel line ends input.
- Level
Easy2 of 10
- Topics
- Simulation, Implementation
- Solved
- No attempts yet
Problem
When a customer withdraws from or deposits money into an ATM, the bank must calculate the customer's new balance correctly. A customer may not overdraw the account by more than 200 dollars. Therefore, any withdrawal that would make the balance less than -200 must be rejected. A negative balance represents an overdraft.
Input
The input contains several transaction lines. Each line contains an integer starting balance, a letter W or D, and an integer amount. W means withdrawal and D means deposit.
The starting balance is between -200 and 10000, inclusive. The amount is between 5 and 400, inclusive.
Input ends with the line 0 W 0, which must not be processed as a transaction.
Output
For each transaction before the terminating line, print one line.
If the transaction is valid, print the new balance. If a withdrawal would make the balance less than -200, print Not allowed.