[cpp] v //九度OJ 教程91 回溯算法之《全排列》 #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; }