雕刻时光

just do it……nothing impossible
  博客园  :: 首页  :: 新随笔  :: 联系 :: 订阅 订阅  :: 管理

排列组合STL实现——pku1731

Posted on 2011-03-18 16:28  huhuuu  阅读(763)  评论(0编辑  收藏  举报
用到STL里的
next_permutation(&a[0],&a[le])//说明a[0]->a[le-1]是自由排列的
View Code
#include<iostream>
#include
<string.h>
#include
<algorithm>
using namespace std;

bool cmp(char a,char b)
{
return a<b;
}

int main()
{
char a[209];
while(gets(a))
{
int le=strlen(a);
sort(
&a[0],&a[le],cmp);
do{
puts(a);
}
while (next_permutation(&a[0],&a[le]));//说明a[0]->a[le-1]是自由排列的
}
return 0;
}