-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathboj10845.cpp
More file actions
87 lines (79 loc) · 2.09 KB
/
Copy pathboj10845.cpp
File metadata and controls
87 lines (79 loc) · 2.09 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
82
83
84
85
86
87
#include <stdio.h>
#include <iostream>
/*
push X: 정수 X를 큐에 넣는 연산이다.
pop: 큐에서 가장 앞에 있는 정수를 빼고, 그 수를 출력한다. 만약 큐에 들어있는 정수가 없는 경우에는 -1을 출력한다.
size: 큐에 들어있는 정수의 개수를 출력한다.
empty: 큐가 비어있으면 1, 아니면 0을 출력한다.
front: 큐의 가장 앞에 있는 정수를 출력한다. 만약 큐에 들어있는 정수가 없는 경우에는 -1을 출력한다.
back: 큐의 가장 뒤에 있는 정수를 출력한다. 만약 큐에 들어있는 정수가 없는 경우에는 -1을 출력한다.
*/
#pragma region
using namespace std;
#define MAX (10000+500)
int N;
int q[MAX];
int pr, pw;
int strCmp(const char *a, const char *b)
{
while(*a && (*a == *b)) ++a, ++b;
return *a-*b;
}
void printQ()
{
for(int i = pr; i < pw; i++)
{
cout<<q[i]<<endl;
}
}
#pragma endregion
int main(void)
{
freopen("input.txt","r", stdin);
cin >> N;
char cmd[100];
pr = pw = 0;
int iter = 0;
for(;iter<N;iter++)
{
cin >> cmd;
// cout << iter << "#==================" << cmd << endl;
// cout<<cmd<<endl;
if(!strCmp(cmd, "push"))
{
int val;
cin >> val;
// cout << "val=" << val << endl;
q[pw++] = val;
}
else if(!strCmp(cmd, "pop"))
{
int val;
val = (pr>=pw) ? -1 : q[pr++];
cout<< val << endl;
}
else if(!strCmp(cmd, "size"))
{
int val;
val = (pr==pw) ? 0 : (pw-pr);
cout<< val << endl;
}
else if(!strCmp(cmd, "empty"))
{
int val;
val = (pr>=pw) ? 1 : 0;
cout << val << endl;
}
else if(!strCmp(cmd, "front"))
{
int val = (pr>=pw) ? -1 : q[pr];
cout << val << endl;
}
else if(!strCmp(cmd, "back"))
{
int val = (pr>=pw) ? -1 : q[pw-1];
cout << val << endl;
}
}
return 0;
}