-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path0024.cpp
55 lines (46 loc) · 976 Bytes
/
0024.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 <iostream>
#include <vector>
#include <functional>
#include <fstream>
#include <array>
#include <utility>
#define N 10
std::ostream &operator<<(std::ostream &os, std::array<int, N> arr) {
os << "(";
for (int i = 0; i < N; i++) {
os << arr[i];
if (i < N-1) {
os << " ";
}
}
os << ")";
return os;
}
void fn2() {
std::array<int, 10> arr = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 };
std::function<void()> permutate = [&arr] () {
int i = 9;
while (arr[i-1] >= arr[i]) {
i = i - 1;
}
int j = 10;
while (arr[j-1] <= arr[i-1]) {
j = j - 1;
}
std::swap(arr[i-1], arr[j-1]);
i++;
j = 10;
while (i < j) {
std::swap(arr[i-1], arr[j-1]);
i++;
j--;
}
};
// the initial permutation counts
for (int i = 1; i < 1000000; i++) {
permutate();
//std::cout << arr << std::endl;
}
std::cout << arr << std::endl;
}
std::vector<std::function<void()>> progs = { fn2 };