1-8全排列-牛客
#include <iostream>
#include <algorithm>
using namespace std;
int main()
{
int n=8;
int a[]={1,2,3,4,5,6,7,8};
do{
for(int i=0;i<n;i++){
cout<<a[i];
if(i!=7) cout<<" ";
}
cout<<endl;
}while(next_permutation(a,a+n));
return 0;
}
全排列模板
#include <iostream>
#include <algorithm>
using namespace std;
void FullPermutation(int a[]){//1-n
do{
for(int i=0;i<3;i++){
cout<<a[i]<<" ";
}
cout<<endl;
}while(next_permutation(a,a+3));
}
int main()
{
int a[]={3,1,2};
sort(a,a+3);
FullPermutation(a);
return 0;
}