Skip to content

Commit

Permalink
refactor ex11_32
Browse files Browse the repository at this point in the history
  • Loading branch information
pezy committed Dec 17, 2014
1 parent c37e0f0 commit 14a9b1e
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 74 deletions.
1 change: 1 addition & 0 deletions ch11/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -98,3 +98,4 @@ std::pair<std::map<std::string, std::vector<int>>::iterator, bool> // return
## [Exercise 11.24 ~ 11.26](ex11_24_25_26.cpp)
## [Exercise 11.27 ~ 11.30](ex11_27_28_29_30.cpp)
## [Exercise 11.31](ex11_31.cpp)
## [Exercise 11.32](ex11_32.cpp)
53 changes: 29 additions & 24 deletions ch11/ex11_32.cpp
Original file line number Diff line number Diff line change
@@ -1,31 +1,36 @@
//! @Alan
//!
//!
//! Exercise 11.32:
//! Using the multimap from the previous exercise, write a program to
//! print the list of authors and their works alphabetically.
//!
//
// 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 <iostream>
#include <map>
#include <set>
#include <string>
#include <algorithm>
#include <vector>

#include <iostream>

using std::string;

int main()
{
//! define and initialize the multimap
std::multimap<std::string, std::string> m = {{"lan","z111"},{"alan","a112"},{"Alan","a113"},{"cWang","g222"}};

//! print the map without sorting
for(const auto &e : m)
std::cout << e.first << " " << e.second << "\n";
std::cout << "\n";



return 0;
}

std::multimap<string, string> map{
{"alan", "DMA"},
{"pezy", "LeetCode"},
{"alan", "CLRS"},
{"wang", "FTP"},
{"pezy", "CP5"},
{"wang", "CPP-Concurrency"}
};
std::map<string, std::multiset<string>> ordermap;
for (const auto &e : map)
ordermap[e.first].insert(e.second);
for (const auto &e : ordermap) {
std::cout << e.first << ": ";
for (const auto &work : e.second)
std::cout << work << " ";
std::cout << std::endl;
}
}
50 changes: 0 additions & 50 deletions ch11/ex11_32_ex.cpp

This file was deleted.

0 comments on commit 14a9b1e

Please sign in to comment.