#include<stdio.h>
#include<stdlib.h>
#include<time.h>
//#define COUNT 50
int main(int argc, char* argv[]){
int tmp=0;
int seats[50]={0};
int check[50]={0};
srand((unsigned)time(NULL));
seats[0]=rand()%50;
check[seats[0]]=1;
printf("seats[0]:%d\n",seats[0]);
for(int i=1;i<50;){
//printf("am in for");
tmp=rand()%50;
if((!check[tmp])&&(seats[i-1]-tmp)!=1&&(seats[i-1]-tmp)!=-1)
{
seats[i++]=tmp;
check[tmp]=1;
}
}
for(int j=0;j<50;j++)
printf(" student:%d\n",seats[j]);
}
大家可以完善一下
#include<stdlib.h>
#include<time.h>
//#define COUNT 50
int main(int argc, char* argv[]){
int tmp=0;
int seats[50]={0};
int check[50]={0};
srand((unsigned)time(NULL));
seats[0]=rand()%50;
check[seats[0]]=1;
printf("seats[0]:%d\n",seats[0]);
for(int i=1;i<50;){
//printf("am in for");
tmp=rand()%50;
if((!check[tmp])&&(seats[i-1]-tmp)!=1&&(seats[i-1]-tmp)!=-1)
{
seats[i++]=tmp;
check[tmp]=1;
}
}
for(int j=0;j<50;j++)
printf(" student:%d\n",seats[j]);
}
大家可以完善一下