要求从M个数中选择N个进行组合。请教!!!在线等

解决方案 »

  1.   

    public static ArrayList changeNumber(int max,int count)
    {
    ArrayList resultList;
    if((max<count)||(count<0))
    {
    throw new Exception("需要两个正参数,并且max应该不小于count。");
    }
    else
    {
    System.Random random=new Random();
    resultList=new ArrayList(count);
    do
    {
    int num=random.Next(max);
    if(!resultList.Contains(num))
    {
    resultList.Add(num);
    }
    }
    while(resultList.Count>count);
    }
    return resultList;
    }
      

  2.   

    public double cal(int min, int max)
            {
                return Max_Value(min, max) / Min_Cal(min);
            }
           private int Max_Value(int min,int max)
           {
               int Maxsum = 1;
               for (; (min - 1) != max; )
               {
                   Maxsum = max * Maxsum;
                   max--;
               }
               return Maxsum;
           }
           private int Min_Cal(int min)
           {
               int minSum = 1;
               for (; min > 0; )
               {
                   minSum = minSum * min;
                   min--;
               }
               return minSum;
           }
    在輸入框里判斷一下必須輸入數字