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
|
#include <iostream>
#include <string>
#include <queue>
using namespace std;
int main() {
cin.tie(0);
cin.sync_with_stdio(0);
int n;
cin >> n;
queue<int> q;
for (int i = 0; i < n; i++) {
string command;
cin >> command;
if (command == "push") {
int data;
cin >> data;
q.push(data);
}
else if (command == "pop") {
if (!q.empty()) {
cout << q.front() << "\n";
q.pop();
}
else {
cout << "-1" << "\n";
}
}
else if (command == "size") {
cout << q.size() << "\n";
}
else if (command == "empty") {
if (q.empty())
cout << "1" << "\n";
else
cout << "0" << "\n";
}
else if (command == "front") {
if (!q.empty()) {
cout << q.front() << "\n";
}
else {
cout << "-1" << "\n";
}
}
else if (command == "back") {
if (!q.empty()) {
cout << q.back() << "\n";
}
else {
cout << "-1" << "\n";
}
}
}
return 0;
}
http://colorscripter.com/info#e" target="_blank" style="color:#e5e5e5text-decoration:none">Colored by Color Scripter
|
http://colorscripter.com/info#e" target="_blank" style="text-decoration:none;color:white">cs |
'Baekjoon' 카테고리의 다른 글
[#11866] 요세푸스 문제 0 (0) | 2020.03.15 |
---|---|
[#2164] 카드 2 (0) | 2020.03.15 |
[#1874] 스택 수열 (0) | 2020.03.15 |
[#4949] 균형잡힌 세상 (0) | 2020.03.15 |
[#9012] 괄호 (0) | 2020.03.15 |