#include<iostream>
#include<vector>
#include<string>
using namespace std;
vector<string> result;
void permute(string& str, int depth, int n){
if(depth == n){
result.push_back(str);
return ;
}
for(int i = depth; i< n; i++){
swap(str[depth],str[i]);
permute(str, depth+1, n);
swap(str[depth],str[i]);
}
}
int main(){
string str;
cin>>str;
permute(str, 0, str.size());
for(int i = 0; i < result.size(); i++){
cout << result[i] << endl;
}
return 0;
}
输入一个字符串,要求输出字符串中字符所有的排列,例如输入"abc",得到"abc","acb","bca","bac","cab","cba"
最新推荐文章于 2022-09-09 21:32:40 发布