口袋中有红、黄、蓝白、黑五种颜色的球若干个。每次从口袋中取出3个不同颜色的球,问有多少种取法。
#include<iostream.h>
void main()
{
enum color{red,yellow,blue,white,black};
enum color pri;
int n,loop,i,j,k;
char c;
n=0;
for(i=red;i<=black;i++)
{
for(j=red;j<=black;j++)
{
if(i!=j)
{
for(k=red;k<=black;k++)
{
if((k!=i)&&(k!=j))
{
n=n+1;
//cout<<i<<j<<k<<endl;
for(loop=1;loop<=3;loop++)
{
switch(loop)
{
case 1:
pri=(enum color)i;
break;
case 2:
pri=(enum color)j;
break;
case 3:
pri=(enum color)k;
break;
}
switch(pri)
{
case red:
cout<<"红";
break;
case yellow:
cout<<"黄";
break;
case blue:
cout<<"蓝";
break;
case white:
cout<<"白";
break;
case black:
cout<<"黑";
break;
}
}
}
cout<<endl;
}
}
}
}
cout<<"共"<<n<<"种方法"<<endl;
}
#include<iostream.h>
void main()
{
enum color{red,yellow,blue,white,black};
enum color pri;
int n,loop,i,j,k;
char c;
n=0;
for(i=red;i<=black;i++)
{
for(j=red;j<=black;j++)
{
if(i!=j)
{
for(k=red;k<=black;k++)
{
if((k!=i)&&(k!=j))
{
n=n+1;
//cout<<i<<j<<k<<endl;
for(loop=1;loop<=3;loop++)
{
switch(loop)
{
case 1:
pri=(enum color)i;
break;
case 2:
pri=(enum color)j;
break;
case 3:
pri=(enum color)k;
break;
}
switch(pri)
{
case red:
cout<<"红";
break;
case yellow:
cout<<"黄";
break;
case blue:
cout<<"蓝";
break;
case white:
cout<<"白";
break;
case black:
cout<<"黑";
break;
}
}
}
cout<<endl;
}
}
}
}
cout<<"共"<<n<<"种方法"<<endl;
}