版权声明:我的就是我的 https://blog.csdn.net/qq_41638851/article/details/89279848
1. 枚举按字典序最小排列开始,不停调用“求下一个排列 ”的方法,STL中提供了一个next_permutation.
next_permutation(p, p+n)
#include<bits/stdc++.h>
using namespace std;
int main() {
int n, p[10];
scanf("%d", &n);
for(int i = 0; i < n; i++) cin>>p[i];
sort(p, p+n); // 排序,得到p的最小排列
do {
for(int i = 0; i < n; i++) cout<<p[i]; // 输出排列p
cout<<endl;
} while(next_permutation(p, p+n)); // 求下一个排列
return 0;
}