用的枚举,输出组合情况。
// MOOC 三色球,取两个,组合的情况
// @author qifeng
// @date 2018/12/9
#include<iostream>
#include<stdlib.h>
using namespace std;
int main()
{
int i;
enum Color{red, yellow, blue};
enum Color first, second; // 也可以将 first second temp 全定义为 int
for ( first = red; first < blue; first = (Color)(first+1))
{
for ( second = Color(first+1); second <= blue; second = Color(second+1))
{
for ( i = 0; i < 2; i++)
{
Color temp;
if (i==0)
{
temp = first;
}
if (i==1)
{
temp = second;
}
switch (temp)
{
case red:
cout << "red ";
break;
case yellow:
cout << "yellow ";
break;
case blue:
cout << "blue ";
break;
default:
cout << "error";
break;
}
}
cout << endl;
}
}
system("pause");
return 0;
}