← Back to problems

23. Bank Account

BEGINNER
BeginnerDESIGNLLDState

Implement a single bank account that processes deposits and withdrawals from a command stream, rejecting withdrawals that would overdraw it.

Implement a single bank account. The balance starts at 0. Process commands from stdin, one per line. Commands: - DEPOSIT <amount> : add <amount> to the balance. Print "OK <balance>" with the new balance. - WITHDRAW <amount> : if the account has at least <amount>, subtract it and print "OK <balance>". Otherwise reject the withdrawal (the balance does not change) and print "DENIED <balance>". - BALANCE : print "BALANCE <balance>" with the current balance. All amounts are positive integers. The account can never go negative; a withdrawal larger than the current balance is denied and leaves the balance unchanged.
Log in to submit a solution

Comments

Log into join the discussion.