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

求:算法
123456

首先:选出1个数字,
然后从剩下的5个数字,按C54的方式排列组合,

总共6*5 = 30种组合

C54,会算,

先挑选1个,该如何写呢?

------解决方案--------------------
晕,这不更简单,用一个for循环完事,

for(int nIndex=1;nIndex<=6;nIndex++)
{

}
------解决方案--------------------
用一个数组,把选中的放在最后一个,其他的随机选
------解决方案--------------------
不需要这么麻烦,用if判断就行,

for(int nIndex=1;nIndex<=6;nIndex++)
{
for(int j=1;j<=6;j++)
{
if (j==nIndex)

{
continue;//排除
}
for(int k=j+1;k<=6;k++)
{
if (k==nIndex)
{
continue;
}
//
...
}
}
}

这样不更简单吗?

探讨

用一个数组,把选中的放在最后一个,其他的随机选