-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPermutation2.AC.cpp
61 lines (49 loc) · 1.04 KB
/
Permutation2.AC.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
/**
* Tittle: 10063 - Knuth's Permutation
* Author: Cheng-Shih, Wong
* Date: 2015/03/14
* File: 10063 - Knuths Permuation.cpp - solve it
*/
// include files
#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
using namespace std;
// definitions
#define FOR(i, a, b) for (int i = (a), _n = (b); i <= _n; ++i)
#define clr(x, v) memset(x, v, sizeof(x))
// declarations
string str;
// functions
void dfs(const string &s, const int l)
{
if (l == str.size())
cout << s << endl;
else
{
FOR(i, 0, s.size())
dfs(s.substr(0, i) + str[l] + s.substr(i), l + 1);
}
}
// main function
int main()
{
freopen("Permutation2.in", "r", stdin);
freopen("Permutation3.out", "w", stdout);
bool nl = false;
// input
while (cin >> str)
{
// solve & output
if (nl)
putchar('\n');
else
nl = true;
dfs("", 0);
}
//F11
fclose(stdin);
fclose(stdout);
return 0;
}