如何穷举出一组数字的所有的组合? 请大家帮个忙:假设我有n个数字,例如:81,13,55,7,99,60……我现在希望将他们三个一组、三个一组地进行分组,那如何才能得到这所有的组合情况啊?叩谢了!!! 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 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; while (count3 < n) { scount[2] = s[count3]; Console.WriteLine("{0} {1} {2}",scount[0],scount[1],scount[2]); count3++; } count2++; } count++; } Console.ReadLine(); }用C#的编写简单的程序,希望采纳 aspose chart属性丢失。求帮助。 关于xsd文件的应用 如何自动生编号 〓在线等回复〓★★如何获得TPanel控件的子控件★★ form之间如何调用设置控件? VS2008的高级问题。。。JS真的那么苯。。。。 请问用在C#中怎么修改计算机名和IP地址? “System.Data.SqlClient.SqlException”类型的未经处理的异常出现在 System.Data.dll 中。 TCP服务器编程CPU占有率过高问题 100分问个问题,,.net,java,我该学什么,请大家教教我!!! 接口是值类型还是引用类型?刚写了个程序,大家都来参考下 接口问题
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;
while (count3 < n)
{
scount[2] = s[count3];
Console.WriteLine("{0} {1} {2}",scount[0],scount[1],scount[2]);
count3++;
}
count2++;
}
count++;
}
Console.ReadLine(); }
用C#的编写简单的程序,希望采纳