-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPermutation2.AC.2.cpp
72 lines (62 loc) · 1.52 KB
/
Permutation2.AC.2.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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
#include <algorithm>
#include <iostream>
#include <cstdlib>
#include <cstring>
#include <cstdio>
using namespace std;
char data[11];
char save[3628800][11];
int used[11];
typedef struct noded
{
char data;
noded* next;
}dnode;
dnode D[11];
dnode* Head;
int Count;
void dfs( int d, int n )
{
if ( d == n ) {
dnode* p = Head;
for ( int i = 0 ; i < n ; ++ i ) {
save[Count][i] = p->data;
p = p->next;
}
save[Count ++][n] = 0;
return;
}
dnode *p = Head,*q = p;
for ( int i = 0 ; i <= d ; ++ i ) {
//²åµã
D[d].data = data[d];
D[d].next = p;
if ( !i ) Head = &D[d];
else q->next = &D[d];
//µÝ¹é
dfs( d+1, n );
//»ØËÝ
if ( !i ) Head = p;
else q->next = p;
q = p;
if ( i < d ) p = p->next;
}
}
int main()
{
freopen("Permutation2.in", "r", stdin);
freopen("Permutation3.out", "w", stdout);
int count = 0;
while ( scanf("%s",data) != EOF ) {
if ( count ++ ) printf("\n");
Count = 1;
memset( save, 0, sizeof(save) );
dfs( 0, strlen(data) );
for ( int i = 1 ; i < Count ; ++ i )
printf("%s\n",save[i]);
}
//F11
fclose(stdin);
fclose(stdout);
return 0;
}