给出一个字符串S(可能有重复的字符),按照字典序从小到大,输出S包括的字符组成的所有排列。例如:S = "1312",
输出为:
1123
1132
1213
1231
1312
1321
2113
2131
2311
3112
3121
3211
1312
1123 1132 1213 1231 1312 1321 2113 2131 2311 3112 3121 3211
#include<stdio.h>
#include<string.h>
#include<algorithm>
using namespace std;
const int N = 11;
char str[N];
int main(){
scanf("%s",str);
int len=strlen(str);
sort(str,str+len);
do{
printf("%s\n",str);
}while(next_permutation(str,str+len));
return 0;
}