题目地址:http://jobdu.sinaapp.com/problem.php?cid=1040&pid=90
C语言源码:
#include<stdio.h>#include<string.h>char s[10],a[10];int mark[10];int d(int i,int n){ int j; if(i==n) { a[n]='\0'; printf("%s\n",a); /*这道题要是这么写就超时 for(j=0;j<n;j++) printf("%c",a[j]); printf("\n");*/ } else { for(j=0;j<n;j++) { if(mark[j]==-1) { a[i]=s[j]; mark[j]=1; d(i+1,n); mark[j]=-1; } } }}int main(){ int len,i; while(scanf("%s",s)!=EOF) { len=(int)strlen(s); for(i=0;i<len;i++) mark[i]=-1; d(0,len); printf("\n"); }}