首页 > 学院 > 开发设计 > 正文

简单枚举类型——植物与颜色

2019-11-06 07:32:12
字体:
来源:转载
供稿:网友

简单枚举类型——植物与颜色

Time Limit: 1000MS Memory Limit: 65536KBSubmit Statistic

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

blueyellowpurple

Example Output

Bluebells are blue.Sunflower are yellow.I don't know about the color purple.

Hint

 请用枚举类型实现。

Author

 lxh
01#include<stdio.h>
02#include<string.h>
03#include<stdlib.h>
04enum color{red, orange, yellow, green, blue, violet, no}k;
05int main()
06{
07    char str[32];
08    while(gets(str))
09    {
10        if(strcmp(str,"red")==0)
11        {
12            k=red;
13        }
14        else if(strcmp(str,"orange")==0)
15        {
16            k=orange;
17        }
18        else if(strcmp(str,"yellow")==0)
19        {
20            k=yellow;
21        }
22        else if(strcmp(str,"green")==0)
23        {
24            k=green;
25        }
26        else if(strcmp(str,"violet")==0)
27        {
28            k=violet;
29        }
30         else if(strcmp(str,"blue")==0)
31        {
32            k=blue;
33        }
34        else
35           k=no;
36        switch(k)
37        {
38            case red:
39                 printf("Rose are red./n");
40                 break;
41            case orange:
42                 printf("Poppies are orange./n");
43                 break;
44            case yellow:
45                 printf("Sunflower are yellow./n");
46                 break;
47            case green:
48                 printf("Grass are green./n");
49                 break;
50            case blue:
51                 printf("Bluebells are blue./n");
52                 break;
53             case violet:
54                 printf("Violets are violet./n");
55                 break;
56             case no:
57                printf("I don't know about the color %s./n",str);
58        }
59    }
60    return 0;
61}

发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表