nyoj_218_Dinner_201312021434

Dinner

时间限制:100 ms  |           内存限制:65535 KB
难度:1
 
描述
Little A is one member of ACM team. He had just won the gold in World Final. To celebrate, he decided to invite all to have one meal. As bowl, knife and other tableware is not enough in the kitchen, Little A goes to take backup tableware in warehouse. There are many boxes in warehouse, one box contains only one thing, and each box is marked by the name of things inside it. For example, if "basketball" is written on the box, which means the box contains only basketball. With these marks, Little A wants to find out the tableware easily. So, the problem for you is to help him, find out all the tableware from all boxes in the warehouse.
 
输入
There are many test cases. Each case contains one line, and one integer N at the first, N indicates that there are N boxes in the warehouse. Then N strings follow, each string is one name written on the box.
输出
For each test of the input, output all the name of tableware.
样例输入
3 basketball fork chopsticks
2 bowl letter
样例输出
fork chopsticks
bowl
提示
The tableware only contains: bowl, knife, fork and chopsticks.
来源
辽宁省10年省赛
 1 #include <stdio.h>
 2 #include <string.h>
 3 
 4 char str[1000][100];
 5 
 6 int cmp(const void *a,const void *b)
 7 {
 8     return *(char *)a - *(char *)b;
 9 }
10 int main()
11 {
12     int n;
13     while(scanf("%d",&n)!=EOF)
14     {
15         int i,j,k;
16         getchar();
17         for(i=0;i<n;i++)
18         scanf("%s",str[i]);
19         //qsort(str,n,sizeof(str[0]),cmp);
20         //for(i=0;i<n;i++)
21         //puts(str[i]);
22         for(k=0,i=0;i<n;i++)
23         {
24             if(strcmp(str[i],"bowl")==0)
25             {
26                 if(k)
27                 printf(" ");
28                 printf("%s",str[i]);
29                 k++;
30             }
31             else if(strcmp(str[i],"chopsticks")==0)
32             {
33                 if(k)
34                 printf(" ");
35                 printf("%s",str[i]);
36                 k++;
37             }
38             else if(strcmp(str[i],"fork")==0)
39             {
40                 if(k)
41                 printf(" ");
42                 printf("%s",str[i]);
43                 k++;
44             }
45             else if(strcmp(str[i],"knife")==0)
46             {
47                 if(k)
48                 printf(" ");
49                 printf("%s",str[i]);
50                 k++;
51             }
52         }
53         printf("
");
54     }
55     return 0;
56 }

//比我想象的简单

原文地址:https://www.cnblogs.com/xl1027515989/p/3453976.html