-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSimulationQueue.cpp
More file actions
78 lines (70 loc) · 1.07 KB
/
SimulationQueue.cpp
File metadata and controls
78 lines (70 loc) · 1.07 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
/*
Problem: Simulation Queue
Description
Perform a sequence of operations over a queue, each element is an integer:
PUSH v: push a value v into the queue
POP: remove an element out of the queue and print this element to stdout (print NULL if the queue is empty)
Input
Each line contains a command (operration) of type
PUSH v
POP
Output
Write the results of POP operations (each result is written in a line)
Example
Input
PUSH 1
PUSH 2
PUSH 3
POP
POP
PUSH 4
PUSH 5
POP
#
Output
1
2
3
Input
PUSH 1
POP
POP
PUSH 4
POP
#
Output
1
NULL
4
*/
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(false); cin.tie(0);
queue<int> qe;
string cmd;
int numb;
do
{
cin >> cmd;
if (cmd == "#") continue;
if (cmd == "PUSH")
{
cin >> numb;
qe.push(numb);
}
if (cmd == "POP")
{
if (qe.empty())
{
cout << "NULL" << endl;
} else
{
int s = qe.front();
qe.pop();
cout << s << endl;
}
}
} while (cmd != "#");
return 0;
}