题目地址:http://ac.jobdu.com/problem.php?cid=1040&pid=90
//九度OJ 教程91 回溯算法之《全排列》
//http://ac.jobdu.com/problem.php?cid=1040&pid=90
#include <stdio.h>
#include<string.h>
#define MAXS 8
int mark[MAXS],count,lenth;
char ans[MAXS],h[MAXS];
void huisu(int k)
{
if(k==lenth){puts(ans);return;}
for(int i=0;i<lenth;i++)
{
if(mark[i])
{
mark[i]=0;
ans[count++]=h[i];
huisu(count);
mark[i]=1;
count--;
}
}
}
int main()
{
while(~scanf("%s",h))
{
lenth=strlen(h);
memset(mark,1,MAXS*sizeof(int));
memset(ans,0,MAXS*sizeof(char));
huisu(count=0);
printf("\n");
}
return 0;
}