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;
}
#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 第5版--练习9.31
- C++ Primer 第5版--练习9.45 & 9.46
- C++ Primer 第5版--练习10.24
- C++ Primer 第5版--练习10.14
- C++ Primer 第5版--练习9.47
- C++ Primer 第5版--练习10.15
- C++ Primer 第5版--练习10.25
- C++ Primer 第5版--练习10.13
- C++ Primer 第5版--练习11.7
- C++ Primer 第5版--练习11.20
- C++ Primer课后练习11.3,11.4,11.7,11.8,11.11,11.12,11.13,11.14
- C++ Primer 第5版--练习10.18
- C++ Primer 第5版--练习10.29
- C++ Primer 第5版--练习10.33
- C++ Primer 第5版--练习9.16
- C++ Primer 第5版--练习9.26
- C++ Primer 第5版--练习10.35
- C++ Primer 第5版--练习10.36.
- C++ Primer 第5版--练习11.33
- C++ Primer 第5版--练习10.11