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.
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.
题解:题意很简单,就是单纯的字符串比较和输出,这里我用了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");
}
}