南阳 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; }
搜索
复制
相关文章推荐
- MySQL取整函数
- 今天第一次使用CSDN博客
- [leetcode] 28.Implement strStr()
- Ubuntu修改默认键盘布局的方法(适用于13.04|14.04)
- 植物大战僵尸2天空之城安卓版发布
- 手机卡未实名真会停机 实名登记办理教程
- 软件测试(第一章)
- 天声人語 20150831
- Java下载网络上的图片
- C++ 映射共享文件到本地
- apache fcgi机制核心实现代码
- 2015年云计算的三大发展趋势
- java相关问题回答
- How to Tell Science Stories with Maps
- WiFi与WLAN的区别
- win10应用安装位置修改方法
- [底层] 为什么Integer.MIN_VALUE-1会等于Integer.MAX_VALUE
- 测试基础 同行评审
- Apache和Tomcat
- testlink