#include<stdio.h>
char Compare[100][100];
int count = 0;
void Swap(char *x, char *y) {//指针类型传递的交换函数
char temp = *y;
*y = *x;
*x = temp;
}
void Perm(char list[],int k,int m){
if(k == m){
int flag1 = 0;
for(int i = 0;i<count;i++){
int flag2 = 0;//相同
for(int j = 0;j<m;j++){
if(Compare[i][j]!=list[j]){
flag2 = 1;//不同
break;
}
}
if(flag2 == 0){
flag1 = 1;//相同
break;
}
}
if(flag1 == 0){//不同
for(int i = 0;i<m;i++){
printf("%c",list[i]);
}
for(int i = 0;i<m;i++){
Compare[count][i] = list[i];
}
count++;
printf("\n");
}
}else{
for(int i = k;i<m;i++){
Swap(&list[k],&list[i]);
Perm(list,k+1,m);
Swap(&list[k],&list[i]);
}
}
}
int main (void)
{
int n;
printf("请输入数:\n");
scanf("%d",&n);
getchar();
char s[n+1];
gets(s);
s[n] = '\0';
//puts(s);
printf("全排列如下:\n");
Perm(s,0,n);
printf("%d\n",count);
}