这个组合情况非常多,在6位数互不相等的情况下有:
具体运行结果在程序产生的result.txt文件里,DEV C++源代码如下:
#include<iostream>
using namespace std;
#include<fstream>
#include <iomanip>
int count=0;
int n=100000;
int *R=new int[n];
ofstream fo("result.txt", ofstream::out);
int Result(int n)
{
for (int k=1;k<=33;k++)
{
R[k]=k;
}
for(int a=1;a<=33;a++)
for(int b=a;b<=33;b++)
for (int c=b;c<=33;c++)
for (int d=c;d<=33;d++)
for (int e=d;e<=33;e++)
for (int f=e;f<=33;f++)
if (((R[a]+R[b]+R[c]+R[d]+R[e]+R[f])==n)&&(R[a]!=R[b])&&(R[a]!=R[c])&&(R[a]!=R[d])&&(R[a]!=R[e])&&(R[a]!=R[f])
&&(R[b]!=R[c])&&(R[b]!=R[d])&&(R[b]!=R[e])&&(R[b]!=R[f])&&(R[c]!=R[d])&&(R[c]!=R[e])&&(R[c]!=R[f])&&(R[d]!=R[e])
&&(R[d]!=R[f])&&(R[e]!=R[f]))
{
if (fo.is_open())
{
fo <<R[a]<<","<<R[b]<<","<<R[c]<<","<<R[d]<<","<<R[e]<<","<<R[f]<<"\n";
}
count++;
cout<<R[a]<<","<<R[b]<<","<<R[c]<<","<<R[d]<<","<<R[e]<<","<<R[f]<<"\n";
}
cout<<"组合数有:"<<count<<"种情况!";
fo.close();
}
int main()
{
Result(89);
return 0;
}