这是一项家庭作业。我即将完成它,但我无法克服最后一个驼峰。 我打印所有可能的数组组合,但我无法弄清楚如何从所有组合中挑选出独特的组合。 我试过这种方式和其他一些变化,但我不能让它工作,我不明白为什么。 大小是包含用于终止输入的-1值的数组长度。 Rowdata是一个最大数量为25的数组。PrintFx只是一个具有四个循环的打印函数来打印最终数组。谢谢, 下面是代码:打印所有C中数组的独特组合...真的很接近我认为
void RearrangeArray(int rowdata[],int Size)
{
int firstindex;//This is the loop control variable which controls the first permutation of the array
int secondindex;//This is the index control variable that controls the second variables in the array
int temp[MAXROW]= {0};
int thirdindex = 0;
for (firstindex = 0; firstindex<=Size-1; firstindex++)
{
for (secondindex=firstindex+1; secondindex<=Size-1; secondindex++)
{
if(rowdata[firstindex]!=rowdata[secondindex] || thirdindex == 0)
{
temp[firstindex]=rowdata[firstindex];
rowdata[firstindex]=rowdata[secondindex];
rowdata[secondindex] = temp[firstindex];
if(rowdata[firstindex] == rowdata[secondindex])
{
thirdindex=thirdindex+1;
}
PrintFx(rowdata, Size);
}
}
}
}
Enter row data: 43101 57784 43101 57784 43101 -1
Combination #1: 57784 43101 43101 57784 43101
Combination #2: 43101 57784 43101 57784 43101
Combination #3: 57784 57784 43101 43101 43101
Combination #4: 43101 43101 57784 57784 43101
Combination #5: 43101 43101 43101 57784 57784
Combination #6: 43101 57784 57784 43101 43101
Combination #7: 43101 57784 43101 43101 57784
不应该也有结果,如[3 1],[2 3 1]等? – 2013-04-20 19:36:42
'打印所有独特的连击' – BLUEPIXY 2013-04-20 19:39:47
这里是一个输出示例...我不认为由BLUEPIXY提供的答案相当有效.....其实我会把它放在主帖 – Liquidmetal 2013-04-20 19:39:58