-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy path27.cpp
More file actions
44 lines (39 loc) · 758 Bytes
/
27.cpp
File metadata and controls
44 lines (39 loc) · 758 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
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
using namespace std;
vector<string> res;
void perm(string str, int begin)
{
if (begin == str.length())
res.push_back(str);
else
{
for (int i = begin; i < str.length(); i++)
{
if (i != begin && str[i] == str[begin]) continue;
swap(str[begin], str[i]);
perm(str, begin + 1);
swap(str[begin], str[i]);
}
}
}
vector<string> Permutation(string str)
{
if (str.length() == 0) return res;
perm(str, 0);
sort(res.begin(), res.end());
return res;
}
int main()
{
ios::sync_with_stdio(false);
string s;
cin >> s;
vector<string> v = Permutation(s);
vector<string>::iterator it;
for (it = v.begin(); it != v.end(); it++)
cout << *it << endl;
return 0;
}