BANK TRANSACTIONS
The cooperative bank in your neighborhood is seeking your help in implementing its computer system. The codes of the bank accounts are positive integers with at most nine digits. Customers perform three types of transactions:
- Deposit amount X euros into account A.
- Withdraw amount X euros from account A.
- Query the balance of account A.
Initially, all accounts are assumed to have a zero balance. To execute a withdrawal, the requested amount must be available in the account; otherwise, an error message is printed.
Problem
Develop a program in one of the IOI languages (PASCAL, C, C++, Java) that reads a sequence of transactions and executes them one by one, in the order they are given.
Input files:
The input files named bankacc.in are text files with the following structure: The first line contains an integer N, the number of transactions that follow. Each of the next N lines represents a transaction and starts with one of the letters "d" (deposit), "w" (withdrawal), or "q" (query). They are followed by integers, separated by a space:
- In the case of a deposit or withdrawal ("d" or "w"), two integers A and X: the account number and the amount.
- In the case of a balance inquiry ("q"), an integer A: the account number.
Output files:
The output files named bankacc.out are text files with the following structure. They contain exactly N lines, one for each transaction that takes place. Each line should contain:
- In the case of a successful deposit or withdrawal, the letter "s" (success).
- In the case of a failed withdrawal due to insufficient funds, the letter "f" (failure).
- In the case of a balance inquiry, an integer: the current balance of the corresponding account.
- ### Constraints:
- 1 Ν 1.000.000
- 1 Α 999.999.999
- 1 Χ 1.000.000.000
- The balance of each bank account will never exceed 1.000.000.000.
Examples of input - output files:
STDIN (bankacc.in)
8
d 6 1000
q 4
d 4 500
q 4
w 4 750
w 6 200
q 6
q 4
STDOUT (bankacc.out)
s
0
s
500
f
s
800
500
Explanation of the example:
The following eight transactions are executed in order:
- Deposit 1000€ to account 6, successful
- Query balance for account 4, balance is zero
- Deposit 500€ to account 4, successful
- Query balance for account 4, balance is 500€
- Withdraw 750€ from account 4, fails because the balance is only 500€
- Withdraw 200€ from account 6, successful
- Query balance for account 6, balance is 800€ (1000-200)
- Query balance for account 4, balance is 500€
Subproblems:
- For test cases with a total value of 10%, the account numbers will be single-digit.
- For test cases with a total value of 50%, the account numbers will be at most six-digit.
Notes:
Formatting: In both the input and the output, each line terminates with a newline
character.
Maximum execution time: 1sec.
Maximum available memory: 64MB.
Headers in the source code: At the beginning of your source code, you should use the following headers.
(* USER: username
LANG: PASCAL
TASK: bankacc *)
for PASCAL coders
/* USER: username
LANG: C
TASK: bankacc */
for C coders
/* USER: username
LANG: C++
TASK: bankacc */
for C++ coders
/* USER: username
LANG: Java
TASK: bankacc */
for Java coders
# USER: username
# LANG: Python
# TASK: bankacc
for Python coders
Comments