网站首页 工作范例 办公范例 个人范例 党团范例 简历范例 学生范例 其他范例 专题范例

C++编程实例

栏目: 笔试题目 / 发布于: / 人气:2.48W

随机分配座位,共50个学生,使学号相邻的同学座位不能相邻(早些时候用c#写的,没有用c改写)。

C++编程实例

static void main(string[] args)

{

int tmp = 0, count = 50;

int[] seats = new int[count];

bool[] students = new bool[count];

om randstudent=new om();

students[seats[0]=(0,count)]=true;

for(int i = 1; i < count; ) {

tmp=(int)(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)

e(student + ” “);

();

}

Tags:编程 实例