https://www.acmicpc.net/problem/10866
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
73
74
75
|
#include <iostream>
#include <deque>
using namespace std;
int main()
{
ios_base::sync_with_stdio(0);
cin.tie(NULL);
cout.tie(NULL);
int cnt;
cin >> cnt;
cin.ignore();
deque<int> dq;
while (cnt--)
{
string cmd;
cin >> cmd;
if (cmd == "push_front")
{
int n;
cin >> n;
dq.push_front(n);
}
else if (cmd == "push_back")
{
int n;
cin >> n;
dq.push_back(n);
}
else if (cmd == "pop_front")
{
if (dq.empty())
{
cout << -1 << '\n';
continue;
}
cout << dq.front() << '\n';
dq.pop_front();
}
else if (cmd == "pop_back")
{
if (dq.empty())
{
cout << -1 << '\n';
continue;
}
cout << dq.back() << '\n';
dq.pop_back();
}
else if (cmd == "size")
{
cout << dq.size() << '\n';
}
else if (cmd == "empty")
{
cout << (dq.empty() ? 1 : 0) << '\n';
}
else if (cmd == "front")
{
cout << ((dq.empty()) ? -1 : dq.front()) << '\n';
}
else if (cmd == "back")
{
cout << (dq.empty() ? -1 : dq.back()) << '\n';
}
}
return 0;
}
Colored by Color Scripter
|
'Algorithm > BOJ' 카테고리의 다른 글
[BOJ]2225번: 합분해(c++) (0) | 2020.04.20 |
---|---|
[BOJ]14002번: 가장 긴 증가하는 부분 수열 4(c++) (0) | 2020.04.20 |
[BOJ]1158번: 요세푸스 문제(c++) (0) | 2020.04.15 |
[BOJ]10845번: 큐(c++) (0) | 2020.04.15 |
[BOJ]1406번: 에디터(c++) (0) | 2020.04.15 |
댓글