- #include <iostream>
- #include <string>
- #include <list>
- #include <map>
- #include <vector>
- #include <utility>
- #include <iomanip> //控制格式输出的,
- using namespace std;
- int main(int argc,char **argv)
- {
- map<string,int> word_count;
- string word;
- while(cin>>word)
- {
- pair<map<string,int>::iterator,bool> ret=word_count.insert(make_pair(word,1));
- if(!ret.second)
- ++ret.first->second;
- }
- for(map<string,int>::iterator iter=word_count.begin();
- iter!=word_count.end();++iter)
- {
- cout<<"string is :"<<setw(10)<<iter->first
- <<" Count is :"<<iter->second<<endl;
- }
- return 0;
- }
c++ primer 习题10.12
最新推荐文章于 2024-10-30 21:53:27 发布