-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path12789.cpp
More file actions
72 lines (66 loc) · 1.23 KB
/
12789.cpp
File metadata and controls
72 lines (66 loc) · 1.23 KB
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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
// 12789. 도키도키 간식드리미
// 2021.05.27
// 자료구조, 스택
#include<iostream>
#include<stack>
#include<queue>
using namespace std;
queue<int> q;
stack<int> s;
int main()
{
int n;
int k;
cin >> n;
for (int i = 0; i < n; i++)
{
cin >> k;
q.push(k);
}
int serviceNum = 1;
while (!q.empty())
{
int cur = q.front();
// 현재 차례인 번호면 간식 받음
if (cur == serviceNum)
{
serviceNum++;
q.pop();
}
else
{
// 대기열에 현재 차례인 번호가 있으면 뺌
// 아니면 대기열에 추가
if (!s.empty() && s.top() == serviceNum)
{
s.pop();
serviceNum++;
}
else
{
s.push(cur);
q.pop();
}
}
}
bool flag = true;
while (!s.empty())
{
int top = s.top();
s.pop();
if (top != serviceNum)
{
flag = false;
}
serviceNum++;
}
if (flag)
{
cout << "Nice" << endl;
}
else
{
cout << "Sad" << endl;
}
return 0;
}