枚举类型

来源:互联网 发布:arraypush php 编辑:程序博客网 时间:2024/04/30 19:31
枚举类型Time Limit: 1000ms, Special Time Limit:2500ms, Memory Limit:32768KBTotal submit users: 133, Accepted users: 132Problem 10494 : No special judgementProblem description  已知枚举类型定义如下:

enum  color{red, yellow, blue, green, white, black};

从键盘输入一整数,显示与该整数对应的枚举常量的英文名称。



Input  输入数据有若干行。每行一个整数。
Output  对每行数据,输出与该整数对应的枚举常量的英文名称,换行。
Sample Input
01
Sample Output
redyellow

代码:

#include <iostream>using namespace std;int main(){enum colors{red,yellow,blue,green,white,black};  int i,j;  colors color;  while(cin>>i)  {  for(j=0;j<=i;j++)  {  switch(i)  {  case 0:color=colors(j);break;  case 1:color=colors(j);break;  case 2:color=colors(j);break;  case 3:color=colors(j);break;  case 4:color=colors(j);break;  case 5:color=colors(j);break;  }  } switch(color){case red: cout<<"red"<<endl;break;case yellow:cout<<"yellow"<<endl;break;case blue:cout<<"blue"<<endl;break;case green:cout<<"green"<<endl;break;case white:cout<<"white"<<endl;break;case black:cout<<"black"<<endl;break;}  }  return 0;}