方法一:使用next_permutation() 函数
#include<bits/stdc++.h>
using namespace std;
int main()
{
string s;
cin>>s;
do{
cout<<s<<endl;
}while(next_permutation(s.begin(),s.end()));
return 0;
}
方法二:dfs
#include<bits/stdc++.h>
using namespace std;
string res,s;
bool book[10];
void dfs(string a,int step)
{
if(step==a.size())
{
cout<<res<<endl;
return;
}
else
{
for(int i=0;i<a.size();i++)
{
if(!book[i])
{
book[i]=true;
res+=a[i];
dfs(a,step+1);
book[i]=false;
res.pop_back();
}
}
}
}
int main()
{
cin>>s;
dfs(s,0);
return 0;
}