-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathBOJ10845.cpp
60 lines (55 loc) · 1.17 KB
/
BOJ10845.cpp
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
#define _CRT_SECURE_NO_WARNINGS
#include <bits/stdc++.h>
using namespace std;
queue<int> q;
int main()
{
int N;
scanf("%d", &N);
for (int i = 0; i < N; ++i) {
string s;
int t;
cin >> s;
if (s == "push") {
scanf("%d", &t);
q.push(t);
}
else if (s == "pop") {
if (q.empty()) {
printf("-1\n");
}
else {
printf("%d\n", q.front());
q.pop();
}
}
else if (s == "empty") {
if (q.empty()) {
printf("1\n");
}
else {
printf("0\n");
}
}
else if (s == "front") {
if (q.empty()) {
printf("-1\n");
}
else {
printf("%d\n", q.front());
}
}
else if (s == "back") {
if (q.empty()) {
printf("-1\n");
}
else {
printf("%d\n", q.back());
}
}
else if (s == "size") {
printf("%d\n", q.size());
}
}
return 0;
}