-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPermutation2.cpp
63 lines (55 loc) · 1.15 KB
/
Permutation2.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
#include <algorithm>
#include <fstream>
#include <functional>
#include <iostream>
#include <list>
#include <queue>
#include <string>
#include <vector>
using namespace std;
ifstream fin("Permutation2.in");
ofstream fout("Permutation2.out");
void solve(string str, string out)
{
if (str.size() == 0)
{
fout << out << '\n';
}
else
{
int size1 = str.size();
int size2 = out.size();
for (int i = 0; i <= size2; ++i)
{
string temp1 = str, temp2 = out;
temp2.insert(temp2.begin() + i, temp1[0]);
temp1.erase(temp1.begin());
solve(temp1, temp2);
}
}
}
int main()
{
ios_base::sync_with_stdio(false);
std::cin.tie(NULL);
bool hi = false;
string str = "";
while (fin >> str)
{
string out = "";
//fin >> str;
// if (!(fin >> str))
// {
// break;
// }
// else
if (hi)
{
fout << '\n';
}
solve(str, out);
hi = true;
}
fout.flush();
return 0;
}