fragment-header
fragment-markdown
홈
로그인
로그아웃
내 블로그
설정
로그인
백준 34455 (C++) Donut Shop
최초 업로드: 2025-10-23 21:00:20
최근 수정 시간: 2025-10-23 21:00:20
게시자: rlatjwls3333
카테고리: 백준
조회수: 10
# [Bronze IV] Donut Shop [문제 링크](https://www.acmicpc.net/problem/34455) ## 문제 설명 <p>The owner of a donut shop spends the day baking and selling donuts.</p> <p>Given the events that happen over the course of the day, your job is to determine the number of donuts remaining when the shop closes.</p> ## 입력 <p>The first line of input contains a non-negative integer, $D$, representing the number of donuts available when the shop first opens.</p> <p>The second line contains a positive integer, $E$, representing the number of events that happen over the course of the day. The next $E$ pairs of input lines describe these events.</p> <p>The first line in the pair contains either the <code>+</code> (plus) symbol, indicating that donuts have been baked, or the <code>-</code> (minus) symbol, indicating that donuts have been sold. The second line in the pair contains a positive integer, $Q$, representing the quantity of donuts associated with the event.</p> <p>For each sale of donuts, the value of $Q$ will be less than or equal to the number of donuts available at that time.</p> ## 출력 <p>Output the non-negative integer, $R$, which is the number of donuts remaining when the shop closes.</p> ## 풀이 '+', '-'가 들어올 때 조건 분기 처리해주면 됩니다. ``` c++ #include<bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(0); cin.tie(0); int d, e; cin >> d >> e; while(e--) { char ch; int q; cin >> ch >> q; if(ch=='+') d+=q; else d-=q; } cout << d; } ```