forked from pezy/CppPrimer
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathex11_32.cpp
31 lines (28 loc) · 911 Bytes
/
ex11_32.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
//
// ex11_32.cpp
// Exercise 11.32
//
// Created by pezy on 12/17/14.
// Copyright (c) 2014 pezy. All rights reserved.
//
// Using the multimap from the previous exercise, write a program to print the
// list of **authors and their works** alphabetically.
#include <map>
#include <set>
#include <string>
#include <iostream>
using std::string;
int main()
{
std::multimap<string, string> authors{
{"alan", "DMA"}, {"pezy", "LeetCode"}, {"alan", "CLRS"},
{"wang", "FTP"}, {"pezy", "CP5"}, {"wang", "CPP-Concurrency"}};
std::map<string, std::multiset<string>> order_authors;
for (const auto& author : authors)
order_authors[author.first].insert(author.second);
for (const auto& author : order_authors) {
std::cout << author.first << ": ";
for (const auto& work : author.second) std::cout << work << " ";
std::cout << std::endl;
}
}