Notice
Recent Posts
Recent Comments
Link
«   2026/06   »
1 2 3 4 5 6
7 8 9 10 11 12 13
14 15 16 17 18 19 20
21 22 23 24 25 26 27
28 29 30
Archives
Today
Total
관리 메뉴

dh-winternagi 님의 블로그

(10773) 제로 본문

백준 (C++)/Solve

(10773) 제로

dh-winternagi 2026. 4. 15. 09:10

https://www.acmicpc.net/problem/10773

단계별로 풀어보기

16단계(스택, 큐, 덱 1) 2번째

 

 

 

#include <iostream>
#include <stack>
using namespace std;

int main() 
{
  ios::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  
  stack<int> s;
  int k, ans= 0;
  
  cin >> k;
  
  while(k--){
    int t;
    
    cin >> t;
    
    t?s.push(t):s.pop();
  }
  
  while(!s.empty()){
    ans+= s.top();
    s.pop();
  }
  
  cout << ans;
  
  return 0;
}

'백준 (C++) > Solve' 카테고리의 다른 글

(4949) 균형잡힌 세상  (0) 2026.04.15
(9012) 괄호  (0) 2026.04.15
(28278) 스택 2  (0) 2026.04.15
(13909) 창문 닫기  (0) 2026.04.15
(17103) 골드바흐 파티션  (0) 2026.04.15