1222 Problem O- dinner - Getting title - string handling -C ++ to achieve

Problem O: Dinner

Time limit: 1 Sec memory limit: 32 MB
submitted: 115 solution: 73

Title Description

Xiao Ming to invite friends home for dinner, but the kitchen cutlery is not enough, so Xiao Ming to the warehouse to find new dishes. Warehouse things are packed in one box, what was inside the box that says above, now Xiao Ming would like to invite you to help identify these dishes mounted boxes.
The title contains only dishes: a bowl (bowl), knives (knife), fork (fork), chopsticks (chopsticks).

Entry

Test input comprising a plurality of sets of data. A first input each integer N, with N represents warehouse boxes.
Then enter the string N, respectively, the box filled with something.

Export

For each input and output warehouse all cutlery name.

Sample input  Copy

3 basketball fork chopsticks
2 bowl letter

Sample output  Copy

fork chopsticks
bowl

Code

Tip: None

#include <iostream>
#include <string>
#include <algorithm>
using namespace std;
int main(){
    int num;
    string s;
    while(scanf("%d",&num)!=EOF){
        getchar();
        for(int i = 0;i < num;i++){
           cin>>s;
           getchar();
           if(s=="bowl"){
               cout<<"bowl";
           }
           else if(s=="knife"){
               cout<<"knife";
           }
           else if(s=="fork"){
               cout<<"fork";
           }           
           else if(s=="chopsticks"){
               cout<<"chopsticks";
           }
           else {
               continue;
           }
           if(i<num-1){
                   cout<<" ";
               }else{
                   cout<<endl;
               } 
        }
    }
}

 

 

Published 20 original articles · won praise 0 · Views 120

Guess you like

Origin blog.csdn.net/weixin_31789689/article/details/104736349