排列组合:
有红,黄,蓝,白,黑五种颜色的球,任意取三个不同颜色的球,有多少种取法?(一个简单的组合题),下面的代码算法没有优化.........要是假如从100个里面取50个,那$@*$@&(*^$@*@&&^^!**
#include<iostream.h>
#include<conio.h>
void main()
{
enum Color {red,yellow,blue,white,black};
int count(0);
Color pri;
clrscr();
for (Color i=red;i<=black;i++)
for (Color j=i+1;j<=black;j++)
for (Color k=j+1;k<=black;k++)
{
count++;
cout.width(10);
for (int t=0;t<=2;t++)
{
switch(t)
{
case 0:pri=Color(i);break;
case 1:pri=Color(j);break;
case 2:pri=Color(k);break;
default:break;
}
switch(pri)
{
case red:cout<<" red";break;
case yellow:cout<<" yellow";break;
case blue:cout<<" blue";break;
case white:cout<<" white";break;
case black:cout<<" black";break;
default :break;
}
}
cout<<endl;
}
cout<<endl<<"Total:"<<count<<endl;
return;
}