문제
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’.
풀이
기존 잔고(balance)와, 입금(D) 또는 출금(W) 유형, 금액(diff)이 주어진다.
![](https://blog.kakaocdn.net/dn/o4hbK/btsAm5GdlBK/o94wm5MkVWxSyIATQ1b2I1/img.png)
입금 또는 출금(-200 이상)이 가능하다면 잔고의 최종 금액을, 불가능하면 "Not allowed"를 출력하면 되는 문제다.
단, 입급인 경우에는 별도의 제한이 없으며, "0 W 0"형식으로 주어지면 loop를 중단해야 한다.
![](https://blog.kakaocdn.net/dn/bilylS/btsAmznexla/OnsXuiRZHTgiqIBx2Zjn3K/img.png)
소스코드
출처
2975번: Transactions
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
www.acmicpc.net
'PS > Baekjoon Online Judge' 카테고리의 다른 글
[백준 02991] 사나운 개 [Java] (2) | 2023.11.21 |
---|---|
[백준 02985] 세 수 [Java] (0) | 2023.11.18 |
[백준 02965] 캥거루 세마리 [Java] (0) | 2023.11.16 |
[백준 02959] 거북이 [Java] (1) | 2023.11.15 |
[백준 02953] 나는 요리사다 [Java] (1) | 2023.11.14 |