#include<iostream> #include<string> #include<vector> #include<map> #include<utility> using namespace std; int main() { map<string,vector<pair<string,string>>> childrenMap; string fmname,childname,childBithday; do{ cout<< "input a family name:" << endl; cin >> fmname; if(!cin) break; vector<pair<string,string>> childVec; pair<map<string,vector<pair<string,string>>>::iterator,bool> ret=childrenMap.insert(make_pair(fmname,childVec)); if(!ret.second) { cout<<"\n Already exist"<< fmname << endl; continue; } cout<<"input child name and birthday" << endl; while(cin >> childname >> childBithday) ret.first->second.push_back(make_pair(childname,childBithday)); cin.clear(); }while(cin); cin.clear(); do { cout << "input a family name to search:" <<endl; cin >> fmname; auto iter=childrenMap.find(fmname); if(iter == childrenMap.end()) { cout<< "I‘m sorry,there is not this family name:" << fmname <<endl; } else { vector<pair<string,string>>::iterator it=iter->second.begin(); for(;it !=iter->second.end();++it) { cout<< (*it).first << "---" << (*it).second << endl; } } }while(cin); return 0; }
时间: 2024-10-11 22:08:53