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;
}
#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;
}
相关文章推荐
- C++ Primer 第5版--练习11.7
- C++ primer 第五版 中文版 练习 11.7 个人code
- C++ Primer课后练习11.3,11.4,11.7,11.8,11.11,11.12,11.13,11.14
- c++ primer 练习5.20
- C++ Primer(第五版)练习3.32
- 读C++ primer 的一些练习
- C++ Primer 课后练习9.51
- c++ primer 9.2.5节练习
- C++ Primer 第五版 5.51节&5.6.3节练习
- C++ primer(第五版) 练习 5.23、5.24、5.25 个人code
- C++ primer(第五版) 练习 6.10 个人code
- C++ Primer 第五版 中文版 练习 13.26
- c++ primer 练习 1.16
- C++ primer 第五版 中文版 练习 10.37 个人code
- C++ primer 第五版 中文版 练习 11.33 个人code
- C++ Primer 第五版 中文版 练习 13.13 个人code
- C++ Primer 第五版 中文版 练习 13.35 个人code
- C++ primer 5 3.3.2&3节练习
- c++ primer 练习 2.26、2.27、2.28、2.29、2.30、2.31
- c++ primer第五版 练习8.4