组合排列

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
", s);
		}while(next_permutation(s, s+len));
	}
	return 0;
}



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