PS/Baekjoon Online Judge

[백준 02975] Transactions [Java]

kimyoungrok 2023. 11. 16. 10:59
728x90

문제

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)이 주어진다.

 

입금 또는 출금(-200 이상)이 가능하다면 잔고의 최종 금액을, 불가능하면 "Not allowed"를 출력하면 되는 문제다.

단, 입급인 경우에는 별도의 제한이 없으며, "0 W 0"형식으로 주어지면 loop를 중단해야 한다.

 


소스코드

보기


출처

 

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

728x90