next_permutation関数は、完全な配置を計算します

トピック:
LANQIAOの文字を並べ替えて、LANQIAO、AAILNOQなどの別の単語を取得します。これらの7文字を使用する必要があり、単語に特定の英語の意味がない場合があることに注意してください。すみません、全部でいくつの単語を並べることができますか。

関連するアイデア:sort + next_permutationメソッドを使用して完全な順列を計算します

#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;
}

おすすめ

転載: blog.csdn.net/qq_43341057/article/details/106059587