Tongji Online Judge
Problem 1002: 全排序问题
#include<stdio.h>
#define MAX 10
void p(char *);
void del(char *, int, char *);
void print();
char str_num[MAX+1], out[MAX];
int main()
{
int i;
char ch;
for(i=1, str_num[0]=0; (ch=getchar())!='/n'; i++,str_num[0]++)
str_num[i]=ch;
p(str_num);
return 0;
}
void p(char * str)
{
int i;
char temp[MAX]={0};
if(str[0]==0) {
print();
return ;
}
for(i=1; i<=str[0]; i++) {
out[str_num[0]-str[0]]=str[i];
del(str, i, temp);
p(temp);
}
}
void del(char * str, int n, char * temp)
{
int i;
for(i=1; i<n; i++) temp[i]=str[i];
for(i=n; i<str[0]; i++) temp[i]=str[i+1];
temp[0]=str[0]-1;
}
void print()
{
int i;
for(i=0; i<str_num[0]; i++) {
putchar(out[i]);
if(i==str_num[0]-1) putchar('/n');
else putchar(' ');
}
}