69,371
社区成员
发帖
与我相关
我的任务
分享
#include<stdio.h>
#include<string.h>
#define N 10
char s[N], t[N];
void convert(char *strSource, char *strTarget, int nLen)
{
int i, j;
char strConvert[10];
if(nLen == 1)
{
strTarget[0] = strSource[0];
printf("%s\n", t);
return;
}
else
{
for(i=0; i<nLen; i++)
{
for(j=0; j<i && strSource[i] != strSource[j]; j++);
if(j == i)
{
strTarget[0] = strSource[i];
memcpy(strConvert, strSource, i);
memcpy(strConvert+i, strSource+i+1, nLen-i-1);
convert(strConvert, strTarget+1, nLen-1);
}
}
}
}
void main()
{
int n;
scanf("%s",s);
memset(t, 0, N);
printf("全排列是:\n");
convert(s, t, strlen(s));
}