A140.数字全排列题解
2026-08-03 18:40:51
发布于:广东
9阅读
0回复
0点赞
在C++标准库(STL)中,有一个函数叫做 next_permutation 名字太长了,有点记不住 这个函数可以为我们生成 的全排列
所以,咱直接套函数!!!
#include<bits/stdc++.h> // 万能头
using namespace std;
int main() {
int n;
cin >> n;
int a[10];
for (int i = 0; i < n; i++) // 初始化数组
a[i] = i + 1;
do { // 一定要用 do-while !!不然第1组会不翼而飞
for (int i = 0; i < n; i++) {
if (i > 0)
cout << " ";
cout << a[i];
}
cout << '\n';
} while (next_permutation(a, a + n)); // 套函数
return 0;
}
备注:next_permutation 用法:next_permutation(首迭代器, 尾迭代器)
点个赞呗!!!!!!!!!!!!!





这里空空如也







有帮助,赞一个