Given a string S (possibly repeated characters), lexicographically from smallest to largest, output all permutations of the characters included in S. For example: S = "1312", the
output is:
1123
1132
1213
1231
1312
1321
2113
2131
2311
3112
3121
3211
Input
input a string S (the length of S <= 9, and only include the Arabic numerals 0 - 9)
Output
output S All permutations of contained characters
Input example
1312
Output example
1123
1132
1213
1231
1312
1321
2113
2131
2311
3112
3121
output is:
1123
1132
1213
1231
1312
1321
2113
2131
2311
3112
3121
3211
Input
input a string S (the length of S <= 9, and only include the Arabic numerals 0 - 9)
Output
output S All permutations of contained characters
Input example
1312
Output example
1123
1132
1213
1231
1312
1321
2113
2131
2311
3112
3121
3211
#include<iostream> #include<cstring> #include<algorithm> using namespace std; int main(){ char s[11]; int a[11]; cin>>s; int len=strlen(s); for(int i=0;i<len;i++){ a[i]=s[i]-'0'; } sort (a, a + flax); do{ for(int i=0;i<len;i++) cout<<a[i]; cout<<"\n"; }while(next_permutation(a,a+len)); return 0; }