• 博客园logo
  • 会员
  • 周边
  • 新闻
  • 博问
  • 闪存
  • 众包
  • 赞助商
  • Chat2DB
    • 搜索
      所有博客
    • 搜索
      当前博客
  • 写随笔 我的博客 短消息 简洁模式
    用户头像
    我的博客 我的园子 账号设置 会员中心 简洁模式 ... 退出登录
    注册 登录
Hug_Sea
博客园    首页    新随笔    联系   管理    订阅  订阅

STL-全排列 next_permutation

// 若使用next_permutation函数,必须先将原序列排序! 
// 另外,库中另一函数prev_permutation与next_permutation相反,由原排列得到字典序中上一次最近排列。
 
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <string>
#include <algorithm>
#include <iostream>
using namespace std;
const int N=14;

char str[N];

int main(){
	
//	freopen("data.in","r",stdin);
//	freopen("data.out","w",stdout);
	
	while(scanf("%s",str)!=EOF){
		int len=strlen(str);
		sort(str,str+len);
		do{
			printf("%s\n",str);
		}while(next_permutation(str,str+len));
	}
	return 0;
}

/* 

输入:
cba

输出:
abc
acb
bac
bca
cab
cba
 
*/

 

posted @ 2012-06-04 19:04  Hug_Sea  阅读(175)  评论(0)    收藏  举报
刷新页面返回顶部
博客园  ©  2004-2025
浙公网安备 33010602011771号 浙ICP备2021040463号-3