Dinner

Dinner

Time limit   1000 ms            Memory limit   32768 kB



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.
Input
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.
Output
For each test of the input, output all the name of tableware.
Sample Input
3 basketball fork chopsticks
2 bowl letter
Sample Output
fork chopsticks
bowl
Hint
The tableware only contains: bowl, knife, fork and chopsticks.


題解:題意很簡單,就是單純的字符串比較和輸出,這裏我用了map容器……



#include<stdio.h>
#include<iostream>
#include<algorithm>
#include<string.h>
#include<stdlib.h>
#include<time.h>
#include<string>
#include<math.h>
#include<map>
#include<queue>
#include<stack>
#define INF 0x3f3f3f3f
#define ll long long
#define For(i,a,b) for(int i=a;i<b;i++)
#define sf(a)  scanf("%d",&a)
#define sff(a,b)  scanf("%d%d",&a,&b)
#define pf(a) printf("%d\n",a)
#define mem(a,b) memset(a,b,sizeof(a))
using namespace std;
char x[100];
int main()
{
    int n;
        map<string,int>m;
        m.clear();
        m["bowl"]=1;m["knife"]=1,m["fork"]=1,m["chopsticks"]=1;
    while(~sf(n))
    {
        int flag=0;
        For(i,0,n)
        {
            scanf("%s",x);
            if(m[x]==1)
            {
                if(flag)
                    printf(" %s",x);
                else
                    printf("%s",x);
                    flag=1;
            }
        }
        printf("\n");
    }
}


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章