码迷,mamicode.com
首页 > 其他好文 > 详细

组合排列

时间:2014-09-23 22:46:45      阅读:161      评论:0      收藏:0      [点我收藏+]

标签:style   blog   io   os   ar   div   sp   art   on   

Input

Input contains a single line with all labels of the requested goods (in random order). Each kind of goods is represented by the starting letter of its label. Only small letters of the English alphabet are used. The number of orders doesn‘t exceed 200.

Output

Output will contain all possible orderings in which the stores manager may visit his warehouses. Every warehouse is represented by a single small letter of the English alphabet -- the starting letter of the label of the goods. Each ordering of warehouses is written in the output file only once on a separate line and all the lines containing orderings have to be sorted in an alphabetical order (see the example). No output will exceed 2 megabytes.

Sample Input

bbjd

Sample Output

bbdj
bbjd
bdbj
bdjb
bjbd
bjdb
dbbj
dbjb
djbb
jbbd
jbdb
jdbb


函数生成排列组合序列
#include <stdio.h>
#include <string.h>
#include <algorithm>
#include <iostream>
using namespace std;

int main()		 
{
	char s[300];
	int len;
	while(scanf("%s", s)!=EOF)
	{
		len = strlen(s);
		sort(s, s+len);
		do
		{
			printf("%s\n", s);
		}while(next_permutation(s, s+len));
	}
	return 0;
}

 




组合排列

标签:style   blog   io   os   ar   div   sp   art   on   

原文地址:http://www.cnblogs.com/yspworld/p/3989105.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!