问题
单词计数程序.
源码
1:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 | /************************************************************************* > File Name: test.11.3.cpp > Author: puruidong > Mail: 1@w1520.com > Created Time: 2014年06月27日 ************************************************************************/ #include<iostream> #include<map> using namespace std; /************************************* 编写你自己的单词计数程序. **********************************************/ int main() { map<string,size_t> word_count;//统计. string word; cout << "输入单词:" << endl; while(cin >> word) { ++word_count[word];//增加次数. } cout << "********************\n输出统计结果\n*****************" << endl; for(const auto &w : word_count) { cout << w.first << "\t>>>\t" << w.second << endl; } return 0; } |