您的位置:首页 > 编程语言 > C语言/C++

c++ primer 11.2.1节 11.7练习

2017-03-30 16:35 253 查看
#include<iostream>

#include<utility>

#include<vector>

#include<map>

#include<string>

using namespace std;

void add(map<string, vector<string>> &a,const string &surname,const string &name)

{
for (auto &v : a)
if (v.first == surname)
{
v.second.push_back(name);
return;
}
a[surname].push_back(name);

}

void print(const map<string, vector<string>> &a)

{
for (auto &v : a)

cout << v.first << ends;
for (auto &name : v.second)
cout << name << ends;
cout << endl;
}

}

int main()

{
vector<string> name = { "洪","宏", };
string surname = "王";
map<string, vector<string>> a = { {surname, name} };
add(a, "王", "建");
print(a);
add(a, "李", "至");
print(a);
system("pause");
return 0;

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息