On-Line Banking
Time limit1sMemory limit128 MB
Simulate a stream of bank commands (create, deposit, withdraw, transfer) over many scenarios and print the result of each request.
- Level
Easy3 of 10
- Topics
- Simulation, Implementation, Hash map, String
- Solved
- No attempts yet
Problem
A central bank is the institution responsible for a country's monetary policy. Among its duties, it monitors and supervises the other banks. Your task is to write a program that acts as a simple supervision tool for monitoring bank accounts: it reads a stream of banking requests, applies each request to the accounts in turn, and reports the result of every request.
Input
The input contains several scenarios.
Each scenario begins with a line containing a single positive integer (), the number of bank accounts that exist at the start of the supervision. Each of the next lines describes one account and contains the account number, a single space, and a non-negative decimal number giving the account's initial balance.
After the accounts come the requests, one per line. Each request line starts with a command, optionally followed by parameters separated by single spaces. The commands are:
Each scenario contains between and requests. The requests of a scenario are followed by a line containing the word end and then one empty line, after which the next scenario begins. The whole input ends with a line containing in place of .
Every account number consists of exactly four decimal digits, a slash character (/), and one more digit that identifies the bank operating the account. Each bank has its own unique code, so the same four-digit number under two different bank codes denotes two different accounts.
Every amount is a non-negative decimal number written with exactly two digits after the decimal point, and no amount exceeds . There are no unnecessary leading zeros: only amounts strictly smaller than may start with a zero.
Output
For every request, print exactly one line. The line starts with the command; if the command carries an amount parameter, print a space and that amount right after the command. Then print a colon (:), a single space, and the result of the operation.
For create, the parameter is the account number, so no amount is printed. If an account with the same number already exists in the same bank, the result is already exists; otherwise create the account with an initial balance of and print ok.
For every command other than create, if any account named in the parameters does not exist, the result is no such account. When the required account (or, for transfer, both accounts) exists, apply the rules below.
deposit: add the amount to the account's balance; the result is alwaysok.withdraw: if the balance is strictly smaller than the amount, the result isinsufficient funds; otherwise subtract the amount and printok.transfer: if the two account numbers are equal (including the bank code), the result issame account. Otherwise, if the source balance is strictly smaller than the amount, the result isinsufficient funds. Otherwise move the money and printokif both accounts belong to the same bank, orinterbankif the transfer crosses banks.
After each scenario, print a line containing end followed by one empty line. After the end of the last scenario, print one more line containing the word goodbye.