-
Notifications
You must be signed in to change notification settings - Fork 0
/
11.07
53 lines (47 loc) · 1.1 KB
/
11.07
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
#include <iostream>
#include <queue>
#include <string>
using namespace std;
int main() {
int N;
cin >> N;
queue<int> q;
for (int i = 0; i < N; i++) {
string command;
cin >> command;
if (command == "push") {
int X;
cin >> X;
q.push(X);
}
else if (command == "pop") {
if (q.empty()) {
cout << -1 << endl;
} else {
cout << q.front() << endl;
q.pop();
}
}
else if (command == "size") {
cout << q.size() << endl;
}
else if (command == "empty") {
cout << (q.empty() ? 1 : 0) << endl;
}
else if (command == "front") {
if (q.empty()) {
cout << -1 << endl;
} else {
cout << q.front() << endl;
}
}
else if (command == "back") {
if (q.empty()) {
cout << -1 << endl;
} else {
cout << q.back() << endl;
}
}
}
return 0;
}