c++ primer 习题10.18

来源:互联网 发布:淘宝网店商标 编辑:程序博客网 时间:2024/06/05 10:35

#include <iostream>
#include <fstream>
#include <string>
#include <sstream>
#include <map>
#include <vector>
using namespace::std;
#define N 6
int main()
{   
    string fam_name,fir_name,find_name;
    map<string,vector<string> > name;
    for(int i=0;i!=N;++i)
    {
    vector<string> first_name;
    cout<<"Input the "<<i+1<<" map element now:"<<endl;
    cout<<"Please input the familly name,end with 'CTRL+Z':"<<endl;
    cin>>fam_name;
    cout<<"Please input the first name,end with 'CTRL+Z':"<<endl;
    while(cin>>fir_name)
    first_name.push_back(fir_name);
    name.insert(make_pair(fam_name,first_name));
    cin.clear();
    }
    cout<<"Please input the familly name you wanna find now:"<<endl;
    cin>>find_name;
    map<string,vector<string> >::iterator iter=name.find(find_name);
    if(iter!=name.end())
    {
    cout<<"The first name of the familly name "<<find_name<<" are:"<<endl;
    for(vector<string>::iterator name_it=iter->second.begin();name_it!=iter->second.end();++name_it)
    cout<<*name_it<<" ";
    cout<<endl;
                        }
    else cout<<"opps...CAN NOT FIND "<<find_name<<endl;
    system("pause");
    return 0;  
    }

原创粉丝点击