forked from Mooophy/Cpp-Primer
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathex11_32_ex.cpp
50 lines (44 loc) · 992 Bytes
/
ex11_32_ex.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
///@Author pezy
///
///Exercise 11.32:
///Using the multimap from the previous exercise, write a program to
///print the list of authors and their works alphabetically.
///
#include <iostream>
#include <map>
#include <set>
#include <string>
using std::string;
using std::multimap;
using std::cout;
using std::endl;
using std::multiset;
int main()
{
multimap<string, string> map
{
{"alan", "google"},
{"pezy", "player"},
{"alan", "bible"},
{"wang", "oh sky"},
{"pezy", "is a programmer"},
{"wang", "sky"}
};
for (auto it=map.begin(); it != map.end(); it=map.upper_bound(it->first))
{
cout << it->first << ":";
multiset<string> set;
for (auto ibeg=it; ibeg != map.upper_bound(it->first); ++ibeg)
set.insert(ibeg->second);
for (auto sbeg=set.begin(); sbeg != set.end(); ++sbeg)
cout << *sbeg << " ";
cout << endl;
}
return 0;
}
///
///output:
///alan:bible google
///pezy:is a programmer player
///wang:oh sky sky
///