-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path24.cpp
More file actions
86 lines (78 loc) · 902 Bytes
/
Copy path24.cpp
File metadata and controls
86 lines (78 loc) · 902 Bytes
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
#include<iostream>
#include<fstream>
using namespace std;
int size;
int* b=new int[size];
int k=1;
ofstream myfile;
void assign()
{
for(int i=0;i<size;i++)
b[i]=-1;
}
void push(int a)
{
//cout<<a<<endl;
int i=0;
for(;i<size&&b[i]!=-1;i++);
b[i]=a;
}
void remove()
{int i=0;
for(;i<size&&b[i]!=-1;i++);
b[i-1]=-1;
}
int has(int a)
{//cout<<a<<endl;
int i=0;
for(;i<size&&b[i]!=-1;i++)
if(b[i]==a)
return 1;
return 0;
}
void out()
{int i=0;
myfile<<k<<"\t";
for(;i<size&&b[i]!=-1;i++)
myfile<<b[i];
myfile<<"\r\n";
k++;
}
void permute(int length)
{
if(length==1)
{
int i=0;
for(;i<size;i++)
{
if(!has(i))
{
push(i);
out();
remove();
}
}
}
else
{int i=0;
/* 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);
myfile.close();
return 0;
}