一考场有50人,分配考号为20050001--20050050,为了防此舞弊,现需动态分配座位,分配座位无规律,要求考号相连的不能在旁边,如何实现该功能?

解决方案 »

  1.   

    用一个while啊,不断的产生随即数,然后按顺序分配给20050001--20050050的考生,把最后一个考生的座位和已经分配掉的作为分别纪录下来,如果随即产生出的数字在已经分配掉的或者和最后一个考生所分配到的座位号差的绝对值是1的话,那么就再产生一个随即数,直到满足条件为止
      

  2.   

    TO:petereggplant() 
    大侠,说的不是很明白,能说具体一些,最好能用代码实现一下吗?
      

  3.   

    timtong(acat) 说的不错,给你个思路就很好了自己可以去写嘛
      

  4.   

    下不为例!!!!public static string ShowMun()
    {
    Random rd=new Random();
    ArrayList zuo=new ArrayList();
    string result="";
    do
    {
    int count=zuo.Count;
    int strRandom=rd.Next(20050001,20050050);
    if(count!=0&&count<50)
    {
    int isAdd=(int)zuo[count-1]-strRandom;
    if(isAdd!=1&&isAdd!=-1)
    {
    zuo.Insert(count,strRandom);
    }
    }
    else if(count==0)
    {
    zuo.Insert(0,strRandom);
    }
    else
    {
    break;
    }
    }
    while(true); foreach(int i in zuo)
    {
    result+=i.ToString()+" ";
    }
    return result;
    }