#include <iostream>
#include <map>
#include <string>
#include <vector>
using namespace std;
int main(int argc, char *argv[])
{
map<string, vector<string>> people;
//根据new_fNmae是否为空,调用不同的if分支。
string new_fName = {"He"} , new_sName;
if(new_fName == "")
{
cout<<"please enter the first name: "<<endl;
while(cin>>new_fName){
cout<<"please enter the second name: "<<endl;
while(cin>>new_sName){
people[new_fName].push_back(new_sName);
}
for(auto &i:people)
{
auto b = i.second.begin(), e = i.second.end();
for(;b!=e;++b)
cout<<i.first<<": "<<*b<<endl;
}
}
}
else
{
cout<<"the first name: "<<new_fName<<endl<<"and please the second name: "<<endl;
while(cin>>new_sName){
people[new_fName].push_back(new_sName);
}
for(auto &i:people)
{
auto b = i.second.begin(), e = i.second.end();
for(;b!=e;++b)
cout<<i.first<<": "<<*b<<endl;
}
}
return 0;
}
c++ primer第五版练习11.7
最新推荐文章于 2022-04-10 14:57:26 发布