forked from lshtar13/PS
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path18258.cc
60 lines (56 loc) · 1.17 KB
/
18258.cc
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
#include <bits/stdc++.h>
using namespace std;
int main(void)
{
int n;
scanf("%d", &n);
queue<int> q;
while (n--)
{
char cmd[10];
scanf("%s", cmd);
if (!strcmp(cmd, "push"))
{
int x;
scanf("%d", &x);
q.push(x);
}
else if (!strcmp(cmd, "pop"))
{
if (q.size() == 0)
printf("%d\n", -1);
else
{
printf("%d\n", q.front());
q.pop();
}
}
else if (!strcmp(cmd, "size"))
{
printf("%ld\n", q.size());
}
else if (!strcmp(cmd, "empty"))
{
printf("%d\n", q.size() ? 0 : 1);
}
else if (!strcmp(cmd, "front"))
{
if (q.size() == 0)
printf("%d\n", -1);
else
{
printf("%d\n", q.front());
}
}
else if (!strcmp(cmd, "back"))
{
if (q.size() == 0)
printf("%d\n", -1);
else
{
printf("%d\n", q.back());
}
}
}
return 0;
}