forked from sitz/UVa-Online-Judge
-
Notifications
You must be signed in to change notification settings - Fork 1
/
10063.cpp
55 lines (52 loc) · 758 Bytes
/
10063.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
#include <bits/stdc++.h>
using namespace std;
char str[15], dummy[15];
void Insert(char c, char ss[], int p)
{
int i, l = strlen(ss);
strcpy(dummy, ss);
if (p == l)
{
dummy[l] = c;
dummy[l + 1] = NULL;
return;
}
for (i = l; i > p; i--)
{
dummy[i] = dummy[i - 1];
}
dummy[p] = c;
dummy[l + 1] = NULL;
}
void recur(int level, char ss[])
{
char temp[100];
strcpy(temp, ss);
if (level == strlen(str))
{
puts(ss);
return;
}
for (int i = 0; i <= level; i++)
{
Insert(str[level], temp, i);
recur(level + 1, dummy);
strcpy(dummy, temp);
}
}
int main()
{
int f = 0;
char temp[15];
while (scanf("%s", str) != EOF)
{
if (f++)
{
putchar('\n');
}
temp[0] = str[0];
temp[1] = NULL;
recur(1, temp);
}
return 0;
}