#include<iostream>
#include<map>
using namespace std;
int main() {
multimap<int, int>m;//不去重的键值对
int n, t, s;
cout << "您要输入几个键值对?" << endl;
cin >> n;
for (int i = 0; i < n; i++) {
cin >> t >> s;
m.insert({ t,s });
}
cout << "==========" << endl;
for (auto j : m) {
cout << j.first << " " << j.second << endl;
}
cout << "键1出现了多少次?===>" << m.count(1) << endl;
cout << "如何精准定位到哪个键值对?" << endl;
auto it = m.begin();
for (; it !=m.end();) {
if ((*it).first==3&&(*it).second==2)it = m.erase(it);
else it++;
}
for (auto j : m) {
cout << j.first << " " << j.second << endl;
}
system("pause");
return 0;
}
/*
输入:
6
1 2
3 2
2 1
3 3
1 1
3 10
*/
/*
输出:
==========
1 2
1 1
2 1
3 2
3 3
3 10
键1出现了多少次?===>2
如何精准定位到哪个键值对?
1 2
1 1
2 1
3 3
3 10
请按任意键继续. . .
*/
STL之multimap的简单用法
最新推荐文章于 2024-01-03 01:15:00 发布