1020: Dinner
Time Limit: 1 Sec Memory Limit:4 MB
Description
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
2 bowl letter
Sample Output
bowl
HINT
The tableware only contains: bowl, knife, fork and chopsticks.
Source
#include <iostream>
#include <cstdio>
#include <vector>
using namespace std ;
int main()
{
freopen("in.txt","r",stdin);
int n ;
string Kitchenware ;
vector<string> svec ;
int i = 0 ;
while (cin >> n)
{
for (i = 0 ; i < n ; ++ i)
{
cin >> Kitchenware ;
svec.push_back(Kitchenware) ;
}
bool flag = false ;
for (i = 0 ; i < n ; ++ i)
{
Kitchenware = svec[i] ;
if (Kitchenware == "bowl" || Kitchenware == "knife" ||
Kitchenware == "fork" || Kitchenware == "chopsticks")
{
if (!flag)
{
cout << Kitchenware ;
}
else
cout << " " << Kitchenware ;
flag = true ;
}
}
cout << endl ;
svec.clear() ;
}
return 0 ;
}
本博客介绍了一道关于在仓库中快速查找指定餐具的算法题目。参赛者需要编写程序帮助角色LittleAi从众多箱子中找出所需的餐具,如碗、刀、叉和筷子等,并通过输入输出样例展示了程序的具体实现。

8323

被折叠的 条评论
为什么被折叠?



