关于next_permutation的用法

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:现阶段只知道这么多,本人只是抛砖引玉,希望各位大神指点指点!!


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值