-
Notifications
You must be signed in to change notification settings - Fork 10
/
Day-180.cpp
55 lines (55 loc) · 1.13 KB
/
Day-180.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
#include <bits/stdc++.h>
using namespace std;
#define int int64_t
void interleave (stack<int>&s) {
queue<int>q;
while (!s.empty()) {
q.push(s.top()); s.pop();
}
int f = q.size();
int n = f/2+(f&1);
for (int i=0; i<n; ++i) {
s.push(q.front());
q.pop();
}
while (!s.empty()) {
if (f&1) {
q.push(s.top());
s.pop();
if (!s.empty()){
q.push(q.front());
q.pop();
}
} else {
if (!s.empty()){
q.push(q.front());
q.pop();
}
q.push(s.top());
s.pop();
}
}
while (!q.empty()) {
s.push(q.front());
q.pop();
}
}
signed main(void){
ios::sync_with_stdio(false);
cin.tie(nullptr);
cout.tie(nullptr);
#ifdef HELL_JUDGE
freopen("input","r",stdin);
freopen("output","w",stdout);
#endif
stack<int>s;
for (int i=5; i>=1; --i) {
s.push(i);
}
interleave(s);
while (!s.empty()) {
cout << s.top() << '\n';
s.pop();
}
return 0;
}