The next_permutation function calculates the full arrangement

Topic:
Rearrange the letters in LANQIAO to get different words, such as LANQIAO, AAILNOQ, etc. Note that these 7 letters must be used, and the words may not have specific English meanings. Excuse me, how many different words can be arranged in total.

Related ideas: Calculate the full permutation through the sort + next_permutation method

#define MAX 100
#include<iostream>
#include<algorithm>
using namespace std;
int main()
{
    
    
	int n,a[MAX];
	scanf("%d",&n);
	for(int i=0; i<n; i++)
		scanf("%d",a+i);
	sort(a,a+n); // 保证数组从小到大排列,因为next_premutation函数是字典排序 
	do{
    
    
		for(int i=0; i<n; i++)
			cout << a[i] << " ";
		cout << endl;
	}while(next_permutation(a,a+n)); // 字典排序,具有一定限制 
	
	
	return 0;
}

Guess you like

Origin blog.csdn.net/qq_43341057/article/details/106059587