next_permutation是STL中的一个函数,头文件是#include<algorithm>,作用是生成全排列,默认是后一个比前一个大
例如aacc,生成全排列后为:acac acca caac caca ccaa ,根据ASCALL码的顺序排列,加上本身共6个!
函数模型:
bool next_permutation(first, last);
bool next_permutation(first,last,cmp); cmp为比较函数,自己定义即可。
CODE:
#include<stdio.h>#include<algorithm>
#include<string.h>
using namespace std;
int main()
{
int len,count=0;
char s[20];
gets(s); //貌似不能用scanf("%c",s[i]),可用scanf("%s",s)直接输入
len=strlen(s);
sort(s,s+len);
while(next_permutation(s,s+len))
{
puts(s);//同理
count++;
}
printf("%d\n",count+1);
return 0;
}
更多更详细的介绍请进 http://www.cplusplus.com/reference/algorithm/next_permutation/
http://www.slyar.com/blog/stl_next_permutation.html
PS:现阶段只知道这么多,本人只是抛砖引玉,希望各位大神指点指点!!
本文详细介绍了C++ STL中的next_permutation函数,包括其头文件引用、基本用法、参数解释及一个实际应用示例。通过实例展示了如何使用此函数生成全排列,并对代码进行了深入解析。
7002

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



