输入几个无重复的字母,将这几个字母的全排列输出出来.比如输入a,b,c,会输出"abc,acb,bac,bca,cba,cab,
答案:2 悬赏:0 手机版
解决时间 2021-04-06 22:34
- 提问者网友:皆是孤独
- 2021-04-06 17:47
输入几个无重复的字母,将这几个字母的全排列输出出来.比如输入a,b,c,会输出"abc,acb,bac,bca,cba,cab,
最佳答案
- 五星知识达人网友:长青诗
- 2021-04-06 18:55
#include
#include
#define N 5
int a[120][N];//a[line][N]
int get_line(int n)
{
int line=n;
while(--n)
line=line*n;
return line;
}
void exchange(int num)
{
int rand_N0,rand_N1,t;
rand_N0=rand()%N;
rand_N1=rand()%N;
t=a[num][rand_N0];
a[num][rand_N0]=a[num][rand_N1];
a[num][rand_N1]=t;
}
int campar(int num0,int num1)
{
int i,times=0;
for(i=0;i if(a[num0][i]==a[num1][i])
times++;
return times;
}
void main()
{
int i,j,num=0,line,clash=0;
line=get_line(N);
for(i=0;i for(j=0;j a[i][j]=j+'a';
while(num if(clash)
clash=0;
else
{
printf("the %3d line is ",num);
for(i=0;i printf(" %c ", a[num][i]);
printf("\n");
num++;
}
exchange(num);
for(i=0;i if(campar(num,i)==N)
clash=1;
}
}
}
#include
#define N 5
int a[120][N];//a[line][N]
int get_line(int n)
{
int line=n;
while(--n)
line=line*n;
return line;
}
void exchange(int num)
{
int rand_N0,rand_N1,t;
rand_N0=rand()%N;
rand_N1=rand()%N;
t=a[num][rand_N0];
a[num][rand_N0]=a[num][rand_N1];
a[num][rand_N1]=t;
}
int campar(int num0,int num1)
{
int i,times=0;
for(i=0;i
times++;
return times;
}
void main()
{
int i,j,num=0,line,clash=0;
line=get_line(N);
for(i=0;i
while(num
clash=0;
else
{
printf("the %3d line is ",num);
for(i=0;i
printf("\n");
num++;
}
exchange(num);
for(i=0;i
clash=1;
}
}
}
全部回答
- 1楼网友:骨子里都是戏
- 2021-04-06 20:27
yjh yhj hyj hjy jhy jyh
我要举报
如以上问答信息为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
大家都在看
推荐资讯