-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path10845.cpp
53 lines (47 loc) · 986 Bytes
/
10845.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
#include <stdio.h>
#include <string.h>
#include <queue>
using namespace std;
queue<int> list;
int main() {
int int_n;
char string_command[20];
int int_arg;
scanf("%d", &int_n);
for (int i = 0; i < int_n; i++) {
scanf("%s %d", string_command, &int_arg);
if (!strcmp(string_command, "push")) {
list.push(int_arg);
}
else if (!strcmp(string_command, "pop")) {
if (list.size() <= 0)
printf("-1\n");
else {
printf("%d\n", list.front());
list.pop();
}
}
else if (!strcmp(string_command, "front")) {
if (list.size() <= 0)
printf("-1\n");
else
printf("%d\n", list.front());
}
else if (!strcmp(string_command, "back")) {
if (list.size() <= 0)
printf("-1\n");
else
printf("%d\n", list.back());
}
else if (!strcmp(string_command, "empty")) {
if (list.size() <= 0)
printf("1\n");
else
printf("0\n");
}
else if (!strcmp(string_command, "size")) {
printf("%d\n", list.size());
}
}
return 0;
}