-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathb.cpp
53 lines (36 loc) · 740 Bytes
/
b.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 <fstream>
const int MAX_QUEUE_SIZE = 1e6;
class Queue{
public:
void push(const int& new_value) {
data[tail++] = new_value;
}
int pop() {
return data[head++];
}
private:
int head = 0;
int tail = 0;
int data[MAX_QUEUE_SIZE];
};
int main() {
std::ifstream fin("queue.in");
std::ofstream fout("queue.out");
int m;
Queue queue;
fin >> m;
for (int i = 0; i < m; i++) {
char type;
int new_value;
fin >> type;
if (type == '+') {
fin >> new_value;
queue.push(new_value);
} else {
fout << queue.pop() << '\n';
}
}
fin.close();
fout.close();
return 0;
}