一共两题: 比较简单的关联容器的习题:
11.31 题目:
编写程序,定义一个作者及其作品。。。。这些省略若干的字。
11.32 题目:
使用上一题定义的multimap编写一个程序,。。。这里也省略 我知道你们不会看的。
下面贴上代码:
/*
* 11.31题
* 作者:无哇无哇
* 邮箱:1369541933@qq.com
*/
#include <iostream>
#include <map>
#include <string>
#include <vector>
using namespace std;
int main()
{
multimap<int, string> ismmap{ { 1,"hh" },{ 1,"xx" },{ 1,"ww" },{ 2,"ss" },{ 2,"dd" } };
auto pit = ismmap.equal_range(1);
for (auto i : ismmap)
{
cout << i.first << " " << i.second << endl;
}
ismmap.erase(pit.first, pit.second);
cout << endl;
for (auto i : ismmap)
{
cout << i.first << " " << i.second << endl;
}
return 0;
}
#include <iostream>
#include <map>
#include <string>
#include <vector>
using namespace std;
int main()
{
multimap<int, string> ismmap{ { 1,"hh" },{ 1,"xx" },{ 1,"ww" },{ 2,"ss" },{ 2,"dd" } };
auto pit = ismmap.equal_range(1);
for (auto i : ismmap)
{
cout << i.first << " " << i.second << endl;
}
return 0;
}