c_cpp C ++ Primer 5th Ex 11.32的手痒一试

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了c_cpp 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
///

以上是关于c_cpp C ++ Primer 5th Ex 11.32的手痒一试的主要内容,如果未能解决你的问题,请参考以下文章

C++Primer 5th Chap10 Generic Algorithms(未完)

C++Primer 5th Chap9 Sequential Container(未完)

C++ Primer 5th笔记(chap 19 特殊工具与技术)链接指示: extern “C“

C++ Primer Lippman 5th 练习 2.27 b

C++ Primer 5th笔记(chap 19 特殊工具与技术)定位 new 表达式

C++ Primer 5th笔记(chap 19 特殊工具与技术)异常类层次