练习11.3:编写你自己的单词记数程序
/*
*C++Primer(第五版)
*练习11.3
*2015/9/22
*问题描述:练习11.3:编写你自己的单词记数程序
*说明:照着P375页copy了一遍
*作者:Nick Feng
*邮箱;nickgreen23@163.com
*/
#include <iostream>
#include <string>
#include <map>
using namespace std;
int main()
{
map<string, size_t> word_count; //string到size_t的空map
string word;
while(cin >> word)
++word_count[word]; //提取word的计数器并将其加1
for(const auto &w : word_count)
cout << w.first << " occurs " << w.second << ((w.second > 1) ? " times" : " time") << endl;
return 0;
}