알고리즘/BOJ

백준 2975번 Transactions

꾸준함. 2021. 5. 9. 22:10

문제 링크입니다: www.acmicpc.net/problem/2975

 

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

간단한 구현 문제였습니다.

 

#include <iostream>
using namespace std;
int main(void)
{
ios_base::sync_with_stdio(0);
cin.tie(0);
while (true)
{
int startingBalance, amount;
char operation;
cin >> startingBalance >> operation >> amount;
if (startingBalance == 0 && operation == 'W' && amount == 0)
{
break;
}
if (operation == 'W')
{
int result = startingBalance - amount;
if (result < -200)
{
cout << "Not allowed\n";
continue;
}
cout << result << "\n";
}
else
{
int result = startingBalance + amount;
cout << result << "\n";
}
}
return 0;
}
view raw .cpp hosted with ❤ by GitHub

 

개발환경:Visual Studio 2017

 

지적, 조언, 질문 환영입니다! 댓글 남겨주세요~

반응형

'알고리즘 > BOJ' 카테고리의 다른 글

백준 2991번 사나운 개  (0) 2021.05.11
백준 2985번 세 수  (0) 2021.05.10
백준 2965번 캥거루 세마리  (0) 2021.05.07
백준 2959번 거북이  (0) 2021.05.07
백준 2953번 나는 요리사다  (0) 2021.05.05