#include <iostream>
#include <iterator>
#include <map>
using
namespace
std;
int
main()
{
multimap<
int
,
int
> gquiz1;
gquiz1.insert(pair<
int
,
int
>(1, 40));
gquiz1.insert(pair<
int
,
int
>(2, 30));
gquiz1.insert(pair<
int
,
int
>(3, 60));
gquiz1.insert(pair<
int
,
int
>(6, 50));
gquiz1.insert(pair<
int
,
int
>(6, 10));
multimap<
int
,
int
>::iterator itr;
cout <<
"\nThe multimap gquiz1 is : \n"
;
cout <<
"\tKEY\tELEMENT\n"
;
for
(itr = gquiz1.begin(); itr != gquiz1.end(); ++itr) {
cout <<
'\t'
<< itr->first <<
'\t'
<< itr->second
<<
'\n'
;
}
cout << endl;
gquiz1.insert(pair<
int
,
int
>(4, 50));
gquiz1.insert(pair<
int
,
int
>(5, 10));
cout <<
"\nThe multimap gquiz1 after adding extra "
"elements is : \n"
;
cout <<
"\tKEY\tELEMENT\n"
;
for
(itr = gquiz1.begin(); itr != gquiz1.end(); ++itr) {
cout <<
'\t'
<< itr->first <<
'\t'
<< itr->second
<<
'\n'
;
}
cout << endl;
multimap<
int
,
int
> gquiz2(gquiz1.begin(), gquiz1.end());
cout <<
"\nThe multimap gquiz2 after assign from "
"gquiz1 is : \n"
;
cout <<
"\tKEY\tELEMENT\n"
;
for
(itr = gquiz2.begin(); itr != gquiz2.end(); ++itr) {
cout <<
'\t'
<< itr->first <<
'\t'
<< itr->second
<<
'\n'
;
}
cout << endl;
cout <<
"\ngquiz2 after removal of elements less than "
"key=3 : \n"
;
cout <<
"\tKEY\tELEMENT\n"
;
gquiz2.erase(gquiz2.begin(), gquiz2.find(3));
for
(itr = gquiz2.begin(); itr != gquiz2.end(); ++itr) {
cout <<
'\t'
<< itr->first <<
'\t'
<< itr->second
<<
'\n'
;
}
int
num;
num = gquiz2.erase(4);
cout <<
"\ngquiz2.erase(4) : "
;
cout << num <<
" removed \n"
;
cout <<
"\tKEY\tELEMENT\n"
;
for
(itr = gquiz2.begin(); itr != gquiz2.end(); ++itr) {
cout <<
'\t'
<< itr->first <<
'\t'
<< itr->second
<<
'\n'
;
}
cout << endl;
cout <<
"gquiz1.lower_bound(5) : "
<<
"\tKEY = "
;
cout << gquiz1.lower_bound(5)->first <<
'\t'
;
cout <<
"\tELEMENT = "
<< gquiz1.lower_bound(5)->second
<< endl;
cout <<
"gquiz1.upper_bound(5) : "
<<
"\tKEY = "
;
cout << gquiz1.upper_bound(5)->first <<
'\t'
;
cout <<
"\tELEMENT = "
<< gquiz1.upper_bound(5)->second
<< endl;
return
0;
}