sort排序 next_permutation全排列


#include<cstdio>
#include<algorithm>
using namespace std;
int main() {
  int n, p[10];
  scanf("%d", &n);
  for(int i = 0; i < n; i++) scanf("%d", &p[i]);
  sort(p, p+n); // 排序,得到p的最小排列
  do {
    for(int i = 0; i < n; i++) printf("%d ", p[i]); // 輸出排列p
    printf("\n");
  } while(next_permutation(p, p+n)); // 求下一個排列
  return 0;

}

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章