[Cpp]
Description: it is a simple question. Just write it in the method in Liu lujia's book, and then you can access
# Include <iostream>
# Include <cstdio>
# Include <cstring>
# Include <algorithm>
Using namespace std;
Void print_permutation (char * p, char * q, int len, int cur)
{
Int I, j;
If (cur = len) printf ("% s \ n", q );
Else for (I = 0; I <len; I ++)
If (! I | p [I]! = P [I-1])
{
Int c1 (0), c2 (0 );
For (j = 0; j <cur; j ++) if (q [j] = p [I]) c1 ++;
For (j = 0; j <len; j ++) if (p [j] = p [I]) c2 ++;
If (c1 <c2)
{
Q [cur] = p [I];
Print_permutation (p, q, len, cur + 1 );
}
}
}
Int main ()
{
// Freopen ("a.txt", "r", stdin );
Char s [15], str [15];
Int n, len;
Scanf ("% d", & n );
While (n --)
{
Memset (s, 0, sizeof (s ));
Scanf ("% s", s );
Len = strlen (s );
Sort (s, s + len );
Memset (str, 0, sizeof (str ));
Print_permutation (s, str, len, 0 );
Printf ("\ n ");
}
Return 0;
}