sdut 1959 简单枚举类型——植物与颜色
2017-07-27 16:57
302 查看
题目链接
Problem Description
请定义具有red, orange, yellow, green, blue, violet六种颜色的枚举类型color,根据输入的颜色名称,输出以下六种植物花朵的颜色:Rose(red), Poppies(orange), Sunflower(yellow), Grass(green), Bluebells(blue), Violets(violet)。如果输入的颜色名称不在枚举类型color中,例如输入purple,请输出I don’t know about the color purple.
Input
输入数据有多行,每行有一个字符串代表颜色名称,颜色名称最多30个字符,直到文件结束为止。
Output
输出对应颜色的植物名称,例如:Bluebells are blue. 如果输入的颜色名称不在枚举类型color中,例如purple, 请输出I don’t know about the color purple.
Example Input
blue
yellow
purple
Example Output
Bluebells are blue.
Sunflower are yellow.
I don’t know about the color purple.
使用枚举类型的时候要用强制类型转换
Problem Description
请定义具有red, orange, yellow, green, blue, violet六种颜色的枚举类型color,根据输入的颜色名称,输出以下六种植物花朵的颜色:Rose(red), Poppies(orange), Sunflower(yellow), Grass(green), Bluebells(blue), Violets(violet)。如果输入的颜色名称不在枚举类型color中,例如输入purple,请输出I don’t know about the color purple.
Input
输入数据有多行,每行有一个字符串代表颜色名称,颜色名称最多30个字符,直到文件结束为止。
Output
输出对应颜色的植物名称,例如:Bluebells are blue. 如果输入的颜色名称不在枚举类型color中,例如purple, 请输出I don’t know about the color purple.
Example Input
blue
yellow
purple
Example Output
Bluebells are blue.
Sunflower are yellow.
I don’t know about the color purple.
使用枚举类型的时候要用强制类型转换
#include<iostream> using namespace std; typedef enum color{ red, orange, yellow, green, blue, violet }color; int main(){ string s; while(cin>>s){ int co; if(s=="red") co = 0; else if(s=="orange") co = 1; else if(s=="yellow") co = 2; else if(s=="green") co = 3; else if(s=="blue") co = 4; else if(s=="violet") co = 5; else co = 6; switch((color) co){//强制类型转换为color类型 case 0:cout<<"Rose are red."<<endl;break; case 1:cout<<"Poppies are orange."<<endl;break; case 2:cout<<"Sunflower are yellow."<<endl;break; case 3:cout<<"Grass are green."<<endl;break; case 4:cout<<"Bluebells are blue."<<endl;break; case 5:cout<<"Violets are violet."<<endl;break; default:cout<<"I don't know about the color "<<s<<"."<<endl;break; } } return 0; }
相关文章推荐
- sdut-1959简单枚举类型——植物与颜色
- Java sdut acm 1959 简单枚举类型——植物与颜色
- 简单枚举类型——植物与颜色 (SDUT 1959)
- sdut1959简单枚举类型——植物与颜色
- SDUT 1959 简单枚举类型——植物与颜色
- sdut_java_简单枚举类型——植物与颜色
- SDUT 简单枚举类型——植物与颜色
- 1959简单枚举类型——植物与颜色
- 简单枚举类型——植物与颜色 (sdut oj)
- 简单枚举类型——植物与颜色
- 简单枚举类型——植物与颜色
- 简单枚举类型——植物与颜色
- 简单枚举类型——植物与颜色
- J - 简单枚举类型——植物与颜色
- 简单枚举类型——植物与颜色(类)
- 简单枚举类型——植物与颜色
- 简单枚举类型——植物与颜色
- 简单枚举类型——植物与颜色
- bca5 简单枚举类型——植物与颜色
- 简单枚举类型——植物与颜色