广博吧

位置:首页 > 学习经验 > 考研

C++编程实例

考研1.71W

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

();

}

标签:实例 编程