32 lines
718 B
C++
32 lines
718 B
C++
#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
|
||
*/
|
||
|