1.字符串全排列:
#include<iostream>
#include<algorithm>
using namespace std;
int main(){
string s;
cin>>s;
cout<<s<<" ";
while(next_permutation(s.begin(),s.end())){
cout<<s<<" ";
}
return 0;
}
结果:
2.int全排列:
#include<iostream>
#include<algorithm>
using namespace std;
int main(){
int a[100],n;
cin>>n;
for(int i=0;i<n;++i){
scanf("%d",&a[i]);
}
//cout<<a[0];
while(next_permutation(a,a+n)){
for(int i=0;i<n;++i){
cout<<a[i]<<" ";
}
cout<<endl;
}
return 0;
}
结果: