Under construction

Still being built. Things may change

On-Line Banking

Time limit1sMemory limit128 MB

Summary
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 AA (0<A≤1000 < A \le 100), the number of bank accounts that exist at the start of the supervision. Each of the next AA 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:

CommandMeaningParsParameters
createCreate a new account1New account number
depositDeposit cash to an account2Account number, amount to deposit
withdrawWithdraw cash from an account2Account number, amount to withdraw
transferWire transfer between accounts3Source account, target account, amount

Each scenario contains between 00 and 10001000 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 00 in place of AA.

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 10000.0010000.00. There are no unnecessary leading zeros: only amounts strictly smaller than 1.001.00 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 00 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 always ok.
  • withdraw: if the balance is strictly smaller than the amount, the result is insufficient funds; otherwise subtract the amount and print ok.
  • transfer: if the two account numbers are equal (including the bank code), the result is same account. Otherwise, if the source balance is strictly smaller than the amount, the result is insufficient funds. Otherwise move the money and print ok if both accounts belong to the same bank, or interbank if 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.

Examples1

  1. Example 1

    Input
    3
    1234/5 100.00
    4321/6 150.20
    5432/5 1600.00
    withdraw 1234/5 20.00
    deposit 1234/5 35.00
    withdraw 1234/5 200.00
    transfer 5432/5 1234/5 100.50
    transfer 5432/5 4321/6 50.00
    create 1234/5
    create 1236/5
    transfer 1236/5 1236/5 100.00
    transfer 1236/5 1234/5 100.00
    withdraw 0000/0 100.00
    deposit 0000/0 0.11
    transfer 1234/5 0000/0 10000.00
    end
    
    1
    9999/9 9.40
    deposit 9999/9 6.92
    withdraw 9999/9 9.68
    withdraw 9999/9 6.64
    end
    
    0
    
    Expected output
    withdraw 20.00: ok
    deposit 35.00: ok
    withdraw 200.00: insufficient funds
    transfer 100.50: ok
    transfer 50.00: interbank
    create: already exists
    create: ok
    transfer 100.00: same account
    transfer 100.00: insufficient funds
    withdraw 100.00: no such account
    deposit 0.11: no such account
    transfer 10000.00: no such account
    end
    
    deposit 6.92: ok
    withdraw 9.68: ok
    withdraw 6.64: ok
    end
    
    goodbye