當前位置:萬佳範文網 >

求職簡歷 >筆試題目 >

C++編程實例

C++編程實例

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

();

}

標籤: 編程 實例
  • 文章版權屬於文章作者所有,轉載請註明 https://wjfww.com/qiuzhi/bishi/jndgqy.html
專題