2025-02-07 10:10:14
2023-02-17 17:03:21
2023-12-25 12:29:46
2023-02-18 14:21:10
2023-05-28 13:28:26
更新时间:2023-02-17 15:29:53 发布时间:24小时内 作者:文/会员上传 下载docx 收藏
2025-02-07 10:10:14
2023-02-17 17:03:21
2023-12-25 12:29:46
2023-02-18 14:21:10
2023-05-28 13:28:26
随机分配座位,共50个学生,使学号相邻的同学座位不能相邻(早些时候用c#写的,没有用c改写)。
static void main(string[] args)
{
int tmp = 0, count = 50;
int[] seats = new int[count];
bool[] students = new bool[count];
system.random randstudent=new system.random();
students[seats[0]=randstudent.next(0,count)]=true;
for(int i = 1; i < count; ) {
tmp=(int)randstudent.next(0,count);
if((!students[tmp])&&(seats[i-1]-tmp!=1) && (seats[i-1] – tmp) != -1) {
seats[i++] = tmp;
students[tmp] = true;
}
}
foreach(int student in seats)
system.console.write(student + ” “);
system.console.read();
}
将本文的Word文档下载到电脑
推荐度: