您的位置:首页 > 其它

南阳 dinner

2015-08-31 18:51 288 查看


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.

此题到是没什么太大的难度,需要注意一下输出格式,最后一个输出的单词后面直接接着回车,而不是接着一个空格之后接回车!
因为不知什么时候是最后一个,所以不能前面”*** “,剩下最后一个”***\n“的形式输出,
而应第一个输出时后面没有空格,后面再输出时前加空格,当退出循环后输出回车的形式输出;

本题大意如下:

小A去仓库区餐具,可是仓库中还有别的货物,我们需要做的就是将标有餐具英文的箱子找出,输出到屏幕上,输入数据有多组,每组数据首先输入一个n,代表有n个箱子,随后输入n个单词,查处餐具后按 *** *** **\n的形式输出。

代码如下:

#include<iostream>
using namespace std;

int main()
{
string s[1000],r,t[5]={"bowl","knife","fork","chopsticks"};
int n,k;
while( cin>>n)   //多组输入n;
{k=0;          //k用来判断空格输出;
for(int i=0;i<n;i++)
{
cin>>s[i];
if(s[i]==t[0]||s[i]==t[1]||s[i]==t[2]||s[i]==t[3])  //判断输入的字符串是否为餐具;
{    if(!k) cout<<s[i];    //只有第一个输入没有空格,此时k为0;
else
cout<<" "<<s[i];  //除第一个单词外,输出前均需有空格;
k++;    //只有有单词为餐具时k值才增加,
}
}
cout<<endl;   //结束时需要加回车;
}
return 0;
}


搜索

复制
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: