Or the two methods, recursion and STL, recursive that is the full array of repeating elements, the problem I did not try to not repeat the elements of the arrangement, because from the topic did not find that there must be duplicate elements ()
Post code:
<span style= "Font-family:courier new;font-size:18px;" > #include <stdio.h> #include <string.h> #include <stdlib.h> #include <algorithm>using Namespace Std;int cmp (const void *a,const void *b) {return * (char *) A-* (char *) b;} int main () {int T;char a[15];scanf ("%d", &t), while (t--) {scanf ("%s", a); int len = strlen (a); Qsort (A,len,sizeof (a[0]) , CMP);p UTS (a); while (Next_permutation (A,a+len)) {puts (a);} Puts ("");} return 0;} </span>
recursion:
<span style= "Font-family:courier new;font-size:18px;" > #include <stdio.h> #include <string.h> #include <stdlib.h>int cmp (const void *a,const void *b) { return * (char *) A-* (char *) b;} void Solve (int len,char *a,char *b,int cur) {int i,j;if (cur = = len) {puts (b); return;} Else{for (i=0; i<len; i++) {if (!i| | (A[i]! = a[i-1])) {int ans1 = 0, Ans2 = 0;for (j=0; j<len; j + +) if (a[i] = = A[j]) ans1++;for (j=0; j<cur; j + +) if (B[j]==a[i]) ans2++;if (ans2 < ans1) {B[cur] = A[i];solve (Len, A, B, cur+1);}}} return;} int main () {int T;char A[15];char b[15];scanf ("%d", &t), while (t--) {memset (A, ' ', sizeof (a)), memset (b, ' n ', sizeof (b)); scanf ("%s", a), int len = strlen (a), Qsort (A,len,sizeof (a[0]), CMP), Solve (len,a,b,0);p UTS ("");} return 0;} </span>
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
UVa 10098 generating Fast (fully arranged)