Skip to content

Instantly share code, notes, and snippets.

@pezy
Created August 28, 2014 13:05
Show Gist options
  • Save pezy/eb6618f13c1fd4421397 to your computer and use it in GitHub Desktop.
Save pezy/eb6618f13c1fd4421397 to your computer and use it in GitHub Desktop.
C++ Primer 5th Ex 11.32的手痒一试
///
///@Author pezy
///@Date Aug, 2014
///@See http://www.douban.com/group/topic/61226023/
///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
///
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment