-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path10845.cpp
72 lines (63 loc) · 1.24 KB
/
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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
//BaekJoon Problem: https://www.acmicpc.net/problem/10845
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int queue[10000];
int top = 0, bottom = 0, num = 0;
void push(int x) {
queue[bottom++] = x;
++num;
}
void pop() {
if (num != 0) {
printf("%d\n", queue[top++]);
--num;
}
else
printf("-1\n");
}
void size() {
printf("%d\n", num);
}
void empty() {
if (num == 0)
printf("1\n");
else
printf("0\n");
}
void front() {
if (num != 0)
printf("%d\n", queue[top]);
else
printf("-1\n");
}
void back() {
if (num != 0)
printf("%d\n", queue[bottom - 1]);
else
printf("-1\n");
}
int main() {
int n;
scanf("%d", &n);
for (int i = 0; i < n; ++i) {
char c[6];
int x;
scanf("%s", &c);
if (!strcmp(c, "push")) {
scanf("%d", &x);
push(x);
}
else if (!strcmp(c, "pop"))
pop();
else if (strcmp(c, "size") == 0)
size();
else if (strcmp(c, "empty") == 0)
empty();
else if (strcmp(c, "front") == 0)
front();
else if (strcmp(c, "back") == 0)
back();
}
return 0;
}