C++编程实例
C++编程实例
随机分配座位,共50个学生,使学号相邻的同学座位不能相邻(早些时候用c#写的,没有用c改写)。static void main(string args){int tmp = 0, count = 50;int seats = new int;bool students = new bool;system.random randstudent=new system.random();students=randstudent.next(0,count)]=true;for(int i = 1; i < count; ) {tmp=(int)randstudent.next(0,count);if((!students)&&(seats-tmp!=1) && (seats – tmp) != -1) {seats = tmp;students = true;}}foreach(int student in seats)system.console.write(student + ” “);system.console.read();}相关推荐: