-
Notifications
You must be signed in to change notification settings - Fork 495
/
Copy pathMultimap.cpp
70 lines (53 loc) Β· 1.03 KB
/
Multimap.cpp
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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
#include<map>
#include<iostream>
using namespace std;
int main(){
int n;
char c;
string s;
multimap<char,string> m;
/*Multimap can be used to store multiple values
for the same key */
cin>>n;
for(int i=0;i<n;i++){
cin>>c>>s;
m.insert(make_pair(c,s));
}
for (auto p:m)
cout<<p.first<<" -> "<<p.second<<endl;
//To erase an object from multimap
auto it =m.begin();
//cout<<it<<" will be removed";
m.erase(it);
auto it2=m.lower_bound('D'); //dog
auto it3=m.upper_bound('D'); //Eyes
for(auto it4=it2;it4!=it3;it4++)
cout<<it4->second<<" , ";
cout<<endl;
cout<<"Cat Removed "<<endl;
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-----
5
A Apple
B Banana
C Cat
D Dog
E Eyes
//------OUTPUT-----
A -> Apple
B -> Banana
C -> Cat
D -> Dog
E -> Eyes
Dog ,
Cat Removed
B -> Banana
D -> Dog
E -> Eyes
*/