-
题目描述:
-
输入一个字符串,按字典序打印出该字符串中字符的所有排列。例如输入字符串abc,则打印出由字符a,b,c所能排列出来的所有字符串abc,acb,bac,bca,cab和cba。
-
输入:
-
每个测试案例包括1行。
输入一个字符串,长度不超过9(可能有字符重复),字符只包括大小写字母。
-
输出:
-
对应每组数据,按字典序输出所有排列。
-
样例输入:
-
abc
-
BCA
-
样例输出:
-
abc acb bac bca cab cba ABC ACB BAC BCA CAB CBA
-
-
#include <cstdio> #include <cstring> #include <algorithm> #define MAX 10 using namespace std; int main(int argc,char* argv[]) { char str[MAX]; while(gets(str)) { int length = strlen(str); sort(str,str+length); puts(str); while(next_permutation(str,str+length)) puts(str); } return 0; }