//五种颜色的小球,枚举:(无序排列组合)
#include
#include
using namespace std;
enum color {red,yellow,blue,white,black}; //声明枚举类型
int main()
{
color pri;
int i, j, k, loop;
int n = 0; //n计数
for (i = red; i <= black; i++)
for (j = red; j <= black; j++)
for (k = red; k <= black; k++)
if ( i != j && i != k && j != k )
{
cout << setw(3) << ++n<<" " ;
for (loop = 1; loop <= 3; loop++)
{
switch (loop)
{
case 1:pri = color(i); break;
case 2:pri = color(j); break;
case 3:pri = color(k); break;
default:break;
}
switch (pri)
{
case red: cout << setw(8) << "red"<<" "; break;
case yellow: cout << setw(8) << "yellow" << " "; break;
case blue: cout << setw(8) << "blue" << " "; break;
case white: cout << setw(8) << "white" << " "; break;
case black: cout << setw(8) << "black" << " "; break;
default: break;
}
}
cout << endl;
}
cout << endl<<"total:"<<n<<endl;
return 0;
}
//五种颜色的小球,枚举:(有序排列)
#include
#include
using namespace std;
enum color { red, yellow, blue, white, black }; //声明枚举类型
int main()
{
color pri;
int i, j, k, loop;
int n = 0; //n计数
for (i = red; i <= blue; i++)
for (j = i+1; j <= white; j++)
for (k = j+1; k <= black; k++)
{
cout << setw(3) << ++n << " ";
for (loop = 1; loop <= 3; loop++)
{
switch (loop)
{
case 1:pri = color(i); break; //pri是color类型,i是int 类型,必须要强制转换类型!!!
case 2:pri = color(j); break;
case 3:pri = color(k); break;
default:break;
}
switch (pri)
{
case red: cout << setw(8) << "red" << " "; break;
case yellow: cout << setw(8) << "yellow" << " "; break;
case blue: cout << setw(8) << "blue" << " "; break;
case white: cout << setw(8) << "white" << " "; break;
case black: cout << setw(8) << "black" << " "; break;
default: break;
}
}
cout << endl;
}
cout << endl << "total:" << n << endl;
return 0;
}