1 #include<stdio.h> 2 3 #include<string.h> 4 int a[27],vis[11],len,k,t,cnt; 5 char str[11],temp[6],b_str[6],jd_str[121][6],c; 6 int judge() 7 { 8 int i; 9 for(i = 0;i < t;i ++) 10 if(!strcmp(jd_str[i],temp)) 11 return 0; 12 strcpy(jd_str[t++],temp); 13 return 1; 14 } 15 16 void dfs(int n) 17 { 18 int i,j; 19 if(n == len && judge()) 20 { 21 printf("%s",temp); 22 if(cnt == 1) 23 printf("%c",c); 24 for(j = len-1;j > 0;j --) 25 printf("%c",temp[j]); 26 printf("%c ",temp[0]); 27 return ; 28 } 29 for(i = 0;i < len;i ++) 30 { 31 if(!vis[i]) 32 { 33 vis[i] = 1; 34 temp[k++] = b_str[i]; 35 dfs(n+1); 36 k--; 37 vis[i] = 0; 38 } 39 } 40 } 41 42 int main() 43 { 44 int i,j,m; 45 while(~scanf("%s",str)) 46 { 47 memset(temp,0,sizeof(temp)); 48 memset(vis,0,sizeof(vis)); 49 memset(a,0,sizeof(a)); 50 memset(b_str,0,sizeof(b_str)); 51 m = k = 0; 52 t = cnt = 0; 53 len = strlen(str); 54 for(i = 0;i < len;i ++) 55 a[str[i]-'a']++; 56 for(i = 0;i < 27;i ++) 57 { 58 if(a[i] % 2) 59 { 60 cnt++; 61 c = i+'a'; 62 } 63 if(cnt > 1) 64 break ; 65 } 66 if(cnt > 1) //判断是否有回文存在 67 printf("no palindrome! "); 68 else if(len == 1) 69 printf("%s ",str); 70 else 71 { 72 for(i = 0;i < 27;i ++) 73 { 74 for(j = 0;j < a[i] >> 1;j ++) 75 b_str[m++] = i+'a'; 76 } 77 len = strlen(b_str); 78 dfs(0); 79 } 80 } 81 return 0; 82 }