11.20
#include <iostream>
#include <map>
#include <string>
using std::string;
using std::map;
using std::cin;
using std::cout;
int main()
{
map<string, size_t> counts;
for(string word; cin >> word;)
{
auto result = counts.insert({ word, 1 });
if(!result.second)
++result.first->second;
}
for(auto const& count : counts)
cout << count.first << " " << count.second << ((count.second > 1) ? " times\n" : " time\n");
}
11.21
while (cin >> word)
++word_count.insert({ word, 0 }).first->second;
对于每一个输入的word
如果能插入进去,则插入{word , 0}。然后递增0 ,变为1
如果关键字已经存在,只递增map的值部分
11.22
std::pair<std::string, std::vector<int>> // argument
std::pair<std::map<std::string, std::vector<int>>::iterator, bool> // return
11.23
multimap<string, string> families;
for (string lname, cname; cin >> cname >> lname; families.emplace(lname, cname));