-
Notifications
You must be signed in to change notification settings - Fork 557
/
18258.cpp
44 lines (42 loc) · 861 Bytes
/
18258.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
// Authored by : BaaaaaaaaaaarkingDog
// Co-authored by : -
// http://boj.kr/ef22176f28054f269d7a61e4356f3660
#include <bits/stdc++.h>
using namespace std;
int main(void) {
ios::sync_with_stdio(0);
cin.tie(0);
queue<int> Q;
int n;
cin >> n;
while(n--){
string q;
cin >> q;
if(q=="push"){
int val;
cin >> val;
Q.push(val);
}
else if(q=="pop"){
if(Q.empty()) cout << -1 << '\n';
else{
cout << Q.front() << '\n';
Q.pop();
}
}
else if(q=="size"){
cout << Q.size() << '\n';
}
else if(q=="empty"){
cout << Q.empty() << '\n';
}
else if(q=="front"){
if(Q.empty()) cout << -1 << '\n';
else cout << Q.front() << '\n';
}
else{ // back
if(Q.empty()) cout << -1 << '\n';
else cout << Q.back() << '\n';
}
}
}