-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPE024.cpp
More file actions
executable file
·47 lines (44 loc) · 1.04 KB
/
PE024.cpp
File metadata and controls
executable file
·47 lines (44 loc) · 1.04 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
#include <iostream>
#include <string>
#include <vector>
std::vector<std::string> result;
void mergesort(std::vector<std::string>& input, int low, int high) {
if (low >= high - 1)
return;
int mid = (low + high) / 2;
mergesort(input, low, mid);
mergesort(input, mid, high);
int l1 = low;
int h1 = mid;
int l2 = mid;
int h2 = high;
std::vector<std::string> temp;
while (l1 < h1 && l2 < h2)
if (input[l1] < input[l2])
temp.push_back(input[l1++]);
else
temp.push_back(input[l2++]);
while (l1 < h1)
temp.push_back(input[l1++]);
while (l2 < h2)
temp.push_back(input[l2++]);
for (int i = 0; i < temp.size(); ++i)
input[i + low] = temp[i];
}
void permute(std::string input, int i = 0){
if(i == input.size() - 1)
result.push_back(input);
else{
for( int j = i; j < input.size(); j++){
std::swap(input[i],input[j]);
permute(input,i+1);
std::swap(input[i],input[j]);
}
}
}
int main(){
permute("0123456789");
mergesort(result,0,result.size());
std::cout<<result[999999]<<endl;
return 0;
}