[문제]

Whenever somebody goes to an ATM to withdraw or deposit money, a calculation has to be done to keep the person's bank balance correct. Your task in this problem is to do such calculations. There is a bank rule that says that a customer may not have an overdraft of more than $200, so any withdrawal that would take the balance below –200 must be stopped. (A minus sign is used to indicate an overdraft, or negative balance).


[입력]

Input consists of a number of lines, each representing a transaction. Each transaction consists of an integer representing the starting balance (between –200 and +10,000), the letter W or the letter D (Withdrawal or Deposit), followed by a second integer representing the amount to be withdrawn or deposited (between 5 and 400). Input will be terminated by a line containing 0 W 0.


[출력]

Output consists of one line for each line of input showing the new balance for each valid transaction If a withdrawal would take the balance below -200, the output must be the words ‘Not allowed’.

백준에서 제시하는 예졔 입출력

 


영어로 되어있어서 그렇지 문제 자체는 쉽다.

ATM기계에서 돈을 빼고 넣는 결과를 출력하는 문제이다.

시작값, W / D, 바뀔값, 결과값을 변수로 잡으면 될 것이다.

 

문제를 간단히 하면 다음과 같다. 

1. 0 W 0 이라는 값이 들어가면 프로그램이 종료되도록 한다.

2. W가 입력되면 시작값 - 바뀔값 = 결과값

3. D가 입력되면 시작값 + 바뀔값 = 결과값

4. 결과값이 -200보다 작을 경우, "Not allowed"라 출력되도록 한다.

 

 

출처: https://www.acmicpc.net/problem/2975

 

+ Recent posts