#include<stdio.h>
#include<string.h>
char res_d
[4 * 3 * 2 * 1][5]; int res_i
; void narabe
(char *d
, int n
) { int i
, j
, len
= strlen(d
); char c
; if (n
<= 1) { for (i
= 0; i
< res_i
; i
++) if (0 == strcmp(res_d
[i
], d
)) return; strcpy(res_d
[res_i
++], d
); return; } for (j
= 0; j
< n
; j
++) { narabe
(d
, n
- 1); c
= d
[len
- n
]; for (i
= 0; i
< n
- 1; i
++) d
[len
- n
+ i
] = d
[len
- n
+ i
+ 1]; d
[len
- n
+ i
] = c
; } } int main
() { char d
[] = "aabc"; int i
; res_i
= 0; narabe
(d
, strlen(d
)); for (i
= 0; i
< res_i
; i
++) printf("%s\n", res_d
[i
]); return 0; }
I2luY2x1ZGU8c3RkaW8uaD4KI2luY2x1ZGU8c3RyaW5nLmg+CmNoYXIgcmVzX2RbNCAqIDMgKiAyICogMV1bNV07IGludCByZXNfaTsgdm9pZCBuYXJhYmUoY2hhciAqZCwgaW50IG4pIHsgaW50IGksIGosIGxlbiA9IHN0cmxlbihkKTsgY2hhciBjOyBpZiAobiA8PSAxKSB7IGZvciAoaSA9IDA7IGkgPCByZXNfaTsgaSsrKSBpZiAoMCA9PSBzdHJjbXAocmVzX2RbaV0sIGQpKSByZXR1cm47IHN0cmNweShyZXNfZFtyZXNfaSsrXSwgZCk7IHJldHVybjsgfSBmb3IgKGogPSAwOyBqIDwgbjsgaisrKSB7IG5hcmFiZShkLCBuIC0gMSk7IGMgPSBkW2xlbiAtIG5dOyBmb3IgKGkgPSAwOyBpIDwgbiAtIDE7IGkrKykgZFtsZW4gLSBuICsgaV0gPSBkW2xlbiAtIG4gKyBpICsgMV07IGRbbGVuIC0gbiArIGldID0gYzsgfSB9IGludCBtYWluKCkgeyBjaGFyIGRbXSA9ICJhYWJjIjsgaW50IGk7IHJlc19pID0gMDsgbmFyYWJlKGQsIHN0cmxlbihkKSk7IGZvciAoaSA9IDA7IGkgPCByZXNfaTsgaSsrKSBwcmludGYoIiVzXG4iLCByZXNfZFtpXSk7IHJldHVybiAwOyB9Cg==