当前位置:网站首页>Full Permutation next_ Permutation() function
Full Permutation next_ Permutation() function
2022-07-16 07:59:00 【Steal the mask and run away】
There is the following code in the header file :
int a[];
do
{
}
while(next_permutation(a,a+n));
produce 1~n The full array code of is as follows :
#include <stdio.h>
#include <algorithm>
using namespace std;
int main(){
int n;
while(scanf("%d",&n)&&n){
int a[1000];
for(int i=0;i<n;i++){
scanf("%d",&a[i]);
}
sort(a,a+n);
do{
for(int i=0;i<n;i++)
printf("%d ",a[i]);
printf("\n");
}while(next_permutation(a,a+n));
}
return 0;
}
For example, the input
3
1 0 2
If there is sort()
Output is
0 1 2
0 2 1
1 0 2
1 2 0
2 0 1
2 1 0
If there is no
The output of
1 0 2
1 2 0
2 0 1
2 1 0
Discovery function next_permutation() It is arranged in dictionary order , And it increases from the current dictionary order in the array to the maximum dictionary order , stay ACM International Collegiate Programming Contest, Egyptian Collegiate Programming Contest (2015) Arab Academy for Science and Technology - Alexandria, November 6th, 2015 A Questions can be used next_permutation().
Original blog :https://www.cnblogs.com/My-Sunshine/p/4985366.html
边栏推荐
猜你喜欢

国内外语音合成公司调研

小白能看懂等Tacotron 中文语音合成实践

还在使用 MySQL 中使用枚举?这些陷阱一定要注意!

源码编译装redis

Installing stand-alone redis under Linux

(1) Input and output

Day 6 of DL

Still using enumeration in MySQL? Pay attention to these traps!

Are you still using the strategy mode to solve if else? Map+ functional interface method is yyds

Basic principle and configuration of switch
随机推荐
Number system conversion and subnet Division
File management - Alibaba cloud OSS learning (I)
Generics of C #
C verification code
MySQL foundation related (important)
源码编译装redis
wordpress中文网站代码下载
DIY a cache
递归实现组合型模型
Day 16 of leetcode
The difference between set, map, weakset and weakmap
Installing redis on Linux
Network cabling overview
项目上线之gzip和pm2管理工具的基本使用
C excel net core reading xlsm
C notes - basics, Q & A, WPF
CCF 202012-2 optimal threshold for period end forecast
Re 正则表达式
Druid database connection pool monitoring page
jsonp原理