-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathboj_10845.cpp
More file actions
81 lines (72 loc) · 1.17 KB
/
boj_10845.cpp
File metadata and controls
81 lines (72 loc) · 1.17 KB
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
76
77
78
79
80
81
//<10845>번 : <큐>
#include <bits/stdc++.h>
using namespace std;
int* Q;
int front;
int back;
void init()
{
Q = new int[2000001];
front = -1;
back = -1;
}
bool empty()
{
return front == back;
}
void push(int x)
{
back++;
Q[back] = x;
}
int pop()
{
if(empty())
return -1;
front++;
return Q[front];
}
int getFront()
{
if(empty())
return -1;
return Q[front+1];
}
int getBack()
{
if(empty())
return -1;
return Q[back];
}
int main()
{
ios::sync_with_stdio(false);
cin.tie(NULL);
init();
int N, x;
string cmd;
cin >> N;
for(int i = 0; i < N; i++)
{
cin >> cmd;
if(cmd == "push")
{
cin >> x;
push(x);
}
else if(cmd == "pop")
cout << pop() << '\n';
else if(cmd == "size")
cout << back-front << '\n';
else if(cmd == "empty")
{
if(empty()) cout << 1 << '\n';
else cout << 0 << '\n';
}
else if(cmd == "front")
cout << getFront() << '\n';
else if (cmd == "back")
cout << getBack() << '\n';
}
return 0;
}