#include <iostream>
#include <vector>
#include <set>
#include <algorithm>
using namespace std;
set<string> res;
void fun(string str, int pos) {
if (str.length() == pos) {
res.insert(str);
return ;
}
for (int i = pos; i < str.length(); i ++) {
swap(str[i], str[pos]);
fun(str, pos + 1);
swap(str[i], str[pos]);
}
}
vector<string> permutation(string str) {
res.clear();
vector<string> vs;
if (str.length() == 0)
return vs;
fun(str, 0);
set<string>::iterator it;
for (it = res.begin(); it != res.end(); it ++)
vs.push_back(*it);
return vs;
}
int main() {
string str = "abc";
vector<string> vs = permutation(str);
for (int i = 0; i < vs.size(); i ++)
cout << vs[i] << endl;
}
字符串全排列
最新推荐文章于 2023-01-31 16:02:43 发布