-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtask62.cpp
More file actions
104 lines (93 loc) · 2.27 KB
/
Copy pathtask62.cpp
File metadata and controls
104 lines (93 loc) · 2.27 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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
/*The cube, 41063625 (3453), can be permuted to produce two other cubes: 56623104
(3843) and 66430125 (4053). In fact, 41063625 is the smallest cube which has exactly
three permutations of its digits which are also cube.
Find the smallest cube for which exactly five permutations of its digits are cube.*/
#include <iostream>
#include <string>
#include <vector>
#include <sstream>
#include <cmath>
#include <algorithm>
using namespace std;
vector<string> FindNextPermutations(const string &);
string FindTheNumber(int)
bool IsCube(const string & )
int main(){
return 0;
}
string FindTheNumber(int n)
{
int i{1};
while(true){
int total{};
stringstream ss;
ss << i;
auto t_array = FindNextPermutations(ss.str());
for(auto & it: t_array)
{
if(isCube(it))
++total;
}
if(total == n)
return i;
++i;
}
}
bool IsCube(const string & )
{
unsighed long val{};
srringstream ss;
ss >> val;
int a = floor(pow(val, 1.0/3.0));
if(fabs(a*a*a - val)<1E-10)
return true;
return false;
}
vector<string> FindNextPermutations(const string & val)
{
vector<string> ar{};
string valt = val;
while(true)
{
string strt{valt};
int j=-1;
for(int i = 0; i < valt.size() - 1; i++)
{
char a_j = valt[i];
char a_jp1 = valt[i+1];
if(aj < a_jp1)
{
bool inc = true;
for(int t = i+2; t < valt.size();t++)
{
char next = a_jp1;
if(next < valt[t])
{
inc = false;
break;
}
else
next = valt[t];
}
if(inc)
{
j = i;
break;
}
}
}
if(j == -1)
break;
for(int t = valt.size() - 1; t=>0; t--)
{
if(valt[t] > valt[j])
{
swap(strt[j],strt[k]);
sort(strt.begin()+j+1,strt.end());
}
}
ar.push_back(strt);
valt = strt;
}
return ar;
}