dh-winternagi 님의 블로그
(12789) 도키도키 간식드리미 본문
https://www.acmicpc.net/problem/12789
단계별로 풀어보기
16단계(스택, 큐, 덱 1) 5번째

#include <iostream>
#include <stack>
using namespace std;
int main()
{
ios::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
int n, x= 1;
stack<int> s;
cin >> n;
for(int i=0;i<n;i++){
int t;
cin >> t;
if(t==x){
x++;
}else{
s.push(t);
}
while(!s.empty()){
if(s.top()==x){
s.pop();
x++;
}else{
break;
}
}
}
cout << (x==n+1 ? "Nice" : "Sad");
return 0;
}'백준 (C++) > Solve' 카테고리의 다른 글
| (2164) 카드2 (0) | 2026.04.15 |
|---|---|
| (18258) 큐 2 (0) | 2026.04.15 |
| (4949) 균형잡힌 세상 (0) | 2026.04.15 |
| (9012) 괄호 (0) | 2026.04.15 |
| (10773) 제로 (0) | 2026.04.15 |
