#include <stdio.h>
#include <string.h>
void exchange(char *a,char *b);
int permutation(char *str,int start,int end);
int main()
{
int end;
char a[100];
printf("Please input an string!\n");
scanf("%s",&a);
end=strlen(a);
printf("The length of a is %d\n",end);
permutation(a,0,end);
return 0;
}
void exchange(char *a,char *b)
{
char temp;
temp=*a;
*a=*b;
*b=temp;
}
int permutation(char *str,int start,int end)
{
if(start==end)
{
printf("%s\n",str);
return 0;
}
else
{
int i;
for(i=start;i<end;i++)
{
exchange(str+start,str+i);
permutation(str,start+1,end);
exchange(str+start,str+i);
}
}
}
//016_wy
#include "stdio.h"
#include "stdlib.h"
#include "string.h"
#define MAX 100;
void Permutation(char *pStr, char *pBegin)
{
char* pTemp;
// printf("the string is %s\n",pStr);
if(!pStr || !pBegin)
return;
// printf("the string is %s\n",pStr);
if(*pBegin == '\0')
printf("%s\n",pStr);
else
{
for(pTemp = pBegin; *pTemp != '\0'; ++pTemp)
{
if(*pTemp == *pBegin && pTemp != pBegin)
continue;
else
{
char temp = *pTemp;
*pTemp = *pBegin;
*pBegin = temp;
Permutation(pStr,pBegin+1);
//»¹Ô×Ö·û´®
temp = *pTemp;
*pTemp = *pBegin;
*pBegin = temp;
}
}
}
}
int main()
{
char* s = malloc(20*sizeof(char));
memset(s,'\0',20*sizeof(char));
printf("please input a string :");
scanf("%s",s);
// printf("the string is %s\n",s);
Permutation(s,s);
return 0;
}