C++-7.2.4-下一个排列(next_permutation)

#include<cstdio>
#include<iostream>
#include<algorithm>
using namespace std;
int main(){
	int p[5]={5,4,3,2,1};
	sort(p,p+5);//数组必须初始化 因为该函数从当前排列按顺序枚举下一个 不初始化只会枚举一个54321; 
	do{
		for(int i=0;i<5;i++)
		cout<<p[i];
		cout<<endl;
	}while(next_permutation(p,p+5));
	system("pause");
	return 0;
}

猜你喜欢

转载自blog.csdn.net/qq_41093189/article/details/79438366