日期:2014-05-17  浏览次数:20970 次

如何穷举出一组数字的所有的组合?
请大家帮个忙:
假设我有n个数字,例如:81,13,55,7,99,60……
我现在希望将他们三个一组、三个一组地进行分组,那如何才能得到这所有的组合情况啊?

叩谢了!!!

------解决方案--------------------
http://www.cnblogs.com/rogerwei/archive/2010/11/18/1880336.html
------解决方案--------------------
 //先输入一个整数,代表你要输入的整数的个数
            int n = Convert.ToInt32(Console.ReadLine());
            //建立一个大小为n的数组并赋值
            int[] s = new int[n];
            for (int i = 0; i < n; i++)
            {
                s[i] = Convert.ToInt32(Console.ReadLine());
            }
            //用while进行穷举,从第一个数字出发,一直到n-1个数字和n个数字,只有两个数字为止
            int count=0,count2,count3;//代表第几个三个一组,第几个数组到了起始位置
            int[] scount = new int[3];
            while(count <n-2)
            {
                scount[0] = s[count];
                count2=count+1;
                while (count2 < n - 1)
                {
                    scount[1] = s[count2];
                    count3 = count2 + 1;