3.1蓝桥杯每日知识点,全排列permutation
next_permutation()函数
- 适用于生成当前序列的下一个排列
- 如果存在下一个排列,则将当前序列更改为下一个排列,并返回true
- 如果当前序列已经是最后一个排列,则将序列更改为第一个排列,并返回false
prev_permutation()函数
- 与上述相反,用于生成当前序列的前一个排列。
- 如果存在上一个排列,则当前序列更改为上一个排列,并返回true
- 如果当前序列已经是第一个排列,则将序列更改为最后一个排列,并返回false
#include<bits/stdc++.h>
using namespace std;
int a[10];
int main()
{
a[1] = 2, a[2] = 3,a[3] = 4,a[4] = 1;
bool tag = true;
while(tag)
{
for(int i = 1;i <= 4; ++ i)cout << a[i] <<' ';
cout << '\n';
tag = next_permutation(a + 1,a + 1 + 4);
}
for(int i = 1;i <= 4; ++ i)cout << a[i] <<' ';
}
错误麻烦评论区指出

浙公网安备 33010602011771号