網站首頁 工作範例 辦公範例 個人範例 黨團範例 簡歷範例 學生範例 其他範例 專題範例

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 + ” “);

();

}