#include <iostream>
#include <algorithm>
using namespace std;
//next_permutation()函数返回的是bool值,排列的范围为[first,last)
int main()
{
int myints[]={1,2,3};
sort(myints,myints+3);
cout<<"The 3! possible permutations with 3 elements:\n";
do
{
cout<<myints[0]<<" "<<myints[1]<<" "<<myints[2]<<endl;
}while(next_permutation(myints,myints+3)); //不要忘记了这个分号
cout<<"*****************************"<<endl;
cout<<"After loop:"<<myints[0]<<" "<<myints[1]<<" "<<myints[2]<<endl;
return 0;
}STL中的全排列next_permutation函数
最新推荐文章于 2022-03-20 00:42:21 发布
本文介绍了一个使用C++标准库函数next_permutation来生成所有可能的排列组合的例子。通过sort函数对数组进行排序,然后利用next_permutation迭代生成所有可能的排列,并将这些排列打印出来。展示了如何在循环结束后获取最后一个排列。
部署运行你感兴趣的模型镜像
您可能感兴趣的与本文相关的镜像
Stable-Diffusion-3.5
图片生成
Stable-Diffusion
Stable Diffusion 3.5 (SD 3.5) 是由 Stability AI 推出的新一代文本到图像生成模型,相比 3.0 版本,它提升了图像质量、运行速度和硬件效率
1万+

被折叠的 条评论
为什么被折叠?



