알고리즘/BOJ

백준 5103번 DVDs

꾸준함. 2021. 3. 28. 04:59

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

 

5103번: DVDs

A local company, “DVDs R Us”, need your help with a stock management system. They sell DVDs on-line from a local warehouse and need to know at any moment how many DVDs of each title they have in stock. DVDs of a particular title have a stock code and a

www.acmicpc.net

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

 

#include <iostream>
#include <string>
#include <algorithm>
using namespace std;
int main(void)
{
ios_base::sync_with_stdio(0);
cin.tie(0);
while (true)
{
string title;
cin >> title;
if (title == "#")
{
break;
}
int M, S, T;
cin >> M >> S >> T;
for (int t = 0; t < T; t++)
{
char transaction;
int cnt;
cin >> transaction >> cnt;
if (transaction == 'S')
{
S = max(0, S - cnt);
}
else
{
S = min(M, S + cnt);
}
}
cout << title << " " << S << "\n";
}
return 0;
}
view raw .cpp hosted with ❤ by GitHub

 

 

개발환경:Visual Studio 2017

 

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

반응형

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

백준 20215번 Cutting Corners  (0) 2021.03.29
백준 19944번 뉴비의 기준은 뭘까?  (3) 2021.03.29
백준 5102번 Sarah's Toys  (0) 2021.03.28
백준 19698번 헛간 청약  (0) 2021.03.27
백준 19602번 Dog Treats  (0) 2021.03.27