您的位置:首页 > 编程语言 > C语言/C++

C++ Primer 第5版--练习11.3

2017-05-11 22:16 375 查看
练习 11.3:编写你自己的单词计数程序。

#include <iostream>
#include <map>

using namespace std;

int main()
{
map<string, size_t> word_count;
string word;
while (cin >> word)
++word_count[word];
for (const auto &w : word_count)
{
cout << "\"" << w.first << "\" occurs: " << w.second
<< ((w.second > 1) ? " times" : " time") << endl;
}
return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  C++Primer 练习