首页 > 代码库 > 组合排列

组合排列

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

bbdjbbjdbdbjbdjbbjbdbjdbdbbjdbjbdjbbjbbdjbdbjdbb

函数生成排列组合序列
#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;}

 




组合排列