-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path20.05.21(stack_and_queue)
More file actions
69 lines (69 loc) · 1.09 KB
/
20.05.21(stack_and_queue)
File metadata and controls
69 lines (69 loc) · 1.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
#define _USE_MATH_DEFINES
#include<iostream>
#include<algorithm>
#include <vector>
#include <fstream>
#include <queue>
#include <stack>
using namespace std;
ifstream inp("input.txt");
ofstream outp("output.txt");
int main() {
int n;
inp >> n;
queue<int>a;
for (int i = 0; i < n; i++) {
int t;
inp >> t;
a.push(t);
}
queue<int> o0, o22;
stack<int> o1, o21;
int k = 0;
for (int i = 0; i < n; i++) {
if (a.front() % 3 == 0) {
o0.push(a.front());
a.pop();
continue;
}
if (a.front() % 3 == 1) {
o1.push(a.front());
a.pop();
}
else {
if (k % 2 == 0) {
o21.push(a.front());
a.pop();
}
else {
o22.push(a.front());
a.pop();
}
}
}
while (!o0.size() == 0) {
outp << o0.front << ' ';
o0.pop();
}
outp << '\n';
while (!o0.size() == 0) {
outp << o0.front << ' ';
o0.pop();
}
outp << '\n';
while (!o1.size() == 0) {
outp << o1.top << ' ';
o1.pop();
}
outp << '\n';
while (!o21.size() == 0) {
outp << o21.top << ' ';
o21.pop();
}
outp << '\n';
while (!o22.size() == 0) {
outp << o22.front << ' ';
o22.pop();
}
outp << '\n';
}