-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
52 lines (41 loc) · 791 Bytes
/
Copy pathmain.cpp
File metadata and controls
52 lines (41 loc) · 791 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
45
46
47
48
49
50
51
52
// ÇóÒ»¸ö×Ö·û´®µÄÈ«ÅÅÁÐ
#include <string>
#include <vector>
#include <set>
using std::vector;
using std::string;
void Permutation(std::vector<string> &vec, string& str, char *begin)
{
if (*begin == '\0')
vec.push_back(str);
else
{
for (char *ch = begin; *ch != '\0'; ++ch)
{
char tmp = *ch;
*ch = *begin;
*begin = tmp;
Permutation(vec, str, begin + 1);
tmp = *ch;
*ch = *begin;
*begin = tmp;
}
}
}
vector<string> Permutation(string str) {
vector<std::string> vec;
if (str.size() > 0)
Permutation(vec, str, const_cast<char *>(str.c_str()));
std::set<string> set(vec.begin(), vec.end());
vector<std::string> vec1;
for (auto element : set)
{
vec1.push_back(element);
}
return vec1;
}
int main()
{
Permutation(string("abc"));
return 0;
}