全排列

给出一个字符串S(可能有重复的字符),按照字典序从小到大,输出S包括的字符组成的所有排列。例如:S = "1312",
输出为:
 
1123
1132
1213
1231
1312
1321
2113
2131
2311
3112
3121
3211
Input
输入一个字符串S(S的长度 <= 9,且只包括0 - 9的阿拉伯数字)
Output
输出S所包含的字符组成的所有排列
Input示例
1312
Output示例
1123
1132
1213
1231
1312
1321
2113
2131
2311
3112
3121
3211


 1 #include<iostream>
 2 #include<cstdio>
 3 #include<map>
 4 #include<cstring>
 5 #include<string>
 6 #include<algorithm>
 7 #include<queue>
 8 #include<vector>
 9 #include<stack>
10 #include<cstdlib>
11 #include<cctype>
12 #include<cstring>
13 #include<cmath>
14 using namespace std;
15 const int inf=0x3f3f3f3f;
16 
17 int main(){
18     char s[15];
19     int len;
20     scanf("%s",s);
21     len=strlen(s);
22     sort(s,s+len);
23     do{
24         puts(s);
25     }while(next_permutation(s,s+len));
26     return 0;
27 }

 

posted @ 2018-04-11 19:37  newmoonn  阅读(102)  评论(0)    收藏  举报