#include<stdio.h>
unsigned char *full_array1(int n,unsigned char P[])
{
int i,j;
char filename[100];
FILE *fp;
static unsigned char d[256],temp;
start:
printf("\n请输入随机数据采样文件名:\n");
scanf("%s",filename);
if((fp=fopen(filename,"rb"))==NULL)
{
printf("没有找到文件:%s\n",filename);
goto start;
}
fread(d,n+1,1,fp);
fclose(fp);
for(i=0;i<=n;i++)
P[i]=i;
for(i=n;i>0;i--)
{
j=(d[i-1]+d[i])%i;
if(j ==0)
{P[j]=P[i];}
temp=P[i];
P[i]=P[j];
P[j]=temp;
}
return(P);
}
void main()
{
int n=0,m=0;
int i =0;
unsigned char P[256];
printf("————————————欢迎使用考场座位排号工具—————————————\n");
printf("请输入总人数(不超过255)\n");
scanf("%d",&n);
printf("请输入每排人数\n");
scanf("%d",&m);
*full_array1(n,P);
printf("排列结果如下表:\n");
for(i=1;i<=n;i++)
{
if(((i-1)%m)==0)
printf("\n");
printf("%3d ",P[i]);
}
}
评论0