Files
Data-Structure/STL/STL-map/multimap.cpp
e2hang 6ca2ae6356 STL
2025-08-13 14:53:22 +08:00

32 lines
718 B
C++
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#include <iostream>
#include <map>
using namespace std;
bool cmp(int a, int b){
return a < b;
}
int main(){
auto cmpl = [](int a, int b){
return a > b;
};
multimap<int, string, bool(*)(int, int)> a(cmp);
multimap<int, string, decltype(cmpl)> b(cmpl);
a.insert({{1,"111"},{2,"222"},{1,"11"},{1,"1"},{2,"22"},{3,"333"}});//emplace只能用make_pair不能直接这么写
//pair<const int, string>Key是const修饰的
for(pair<int, string> x : a){
cout << x.first << ", " << x.second << " ";
}
cout << endl;
cout << a.find(1)->second << " " << a.count(1) << endl;
a.erase(a.find(1));
cout << a.find(1)->second << " " << a.count(1) << endl;
return 0;
}
/*
1, 111 1, 11 1, 1 2, 222 2, 22 3, 333
111 3
11 2
*/