-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathmultimap.cpp
More file actions
52 lines (42 loc) · 789 Bytes
/
multimap.cpp
File metadata and controls
52 lines (42 loc) · 789 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
//Multiple elements can have same kay
#include<iostream>
#include<map>
#include<string>
using namespace std;
int main(){
multimap<char,string> m;
int n;
cin>>n;
for(int i=0; i<n; i++){
char ch;
string s;
cin>>ch>>s;
m.insert(make_pair(ch,s));
}
auto it = m.begin();
m.erase(it);
auto it2 = m.lower_bound('b'); //batman
auto it3 = m.upper_bound('d'); //elephant
for(auto it4=it2; it4!=it3; it4++){
cout<<it4->second<<", "<<endl;
}
//search for cat
auto f = m.find('c');
if(f->second=="cat"){
m.erase(f);
}
for(auto p:m){
cout<<p.first<<" -> "<<p.second<<endl;
}
return 0;
/*..................Input............
7
b batman
a apple
a angry
b boat
c cat
d dog
e elephant
*/
}