-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path32.cpp
More file actions
104 lines (96 loc) · 1.29 KB
/
Copy path32.cpp
File metadata and controls
104 lines (96 loc) · 1.29 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
#include<iostream>
#include<fstream>
using namespace std;
int size;
int* b=new int[size];
int k=1;
int* ans=new int[9001];
ofstream myfile;
void assign()
{
for(int i=0;i<size;i++)
b[i]=-1;
}
void push(int a)
{
//cout<<a<<endl;
int i=1;
for(;i<size&&b[i]!=-1;i++);
b[i]=a;
}
void remove()
{int i=1;
for(;i<size&&b[i]!=-1;i++);
b[i-1]=-1;
}
int has(int a)
{//cout<<a<<endl;
int i=1;
for(;i<size&&b[i]!=-1;i++)
if(b[i]==a)
return 1;
return 0;
}
void out()
{int i=1;
int d1=1,d2=1,d3=1,d4=1,d5=1,d6=1,d7=1;
//myfile<<k<<"\t";
//for(;i<size&&b[i]!=-1;i++)
d1=b[1];
d2=b[2]*1000+b[3]*100+b[4]*10+b[5];
d3=b[1]*10+b[2];
d4=b[3]*100+b[4]*10+b[5];
d5=b[1]*100+b[2]*10+b[3];
d6=+b[4]*10+b[5];
d7=b[6]*1000+b[7]*100+b[8]*10+b[9];
if((d1*d2==d7)||(d3*d4==d7)||(d5*d6==d7))
{ans[d7-1000]=1;
//cout<<d7<<endl;
}
//myfile<<b[i];
//myfile<<"\r\n";
//k++;
}
void permute(int length)
{
if(length==1)
{
int i=1;
for(;i<size;i++)
{
if(!has(i))
{
push(i);
out();
remove();
}
}
}
else
{int i=1;
/* if(length==size)
i=2;
*/for(;i<size;i++)
{//cout<<i<<"\t"<<length<<endl;
if(!has(i))
{
push(i);
permute(length-1);
remove();
}
}
}
}
int main()
{myfile.open ("24.txt");
size=10;
assign();
permute(size-1);
myfile.close();
int anss=0;
for(int i=0;i<9001;i++)
if(ans[i]>0)
{anss+=(i+1000);cout<<i+1000<<endl;}
cout<<anss;
return 0;
}