网站首页  词典首页

请输入您要查询的范文:

 

标题 C++编程实例
范文

C++编程实例

  随机分配座位,共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();

  }

随便看

 

范文大全网提供教案、简历、作文、工作总结等各类优秀范文及写作素材,是综合性免费范文平台。

 

Copyright © 2004-2023 triyia.com All Rights Reserved
更新时间:2025/2/6 8:45:30