非专业程序员

  :: 首页 :: 博问 :: 闪存 :: 新随笔 :: 联系 :: 订阅 订阅 :: 管理 ::
  1. #include <iostream>
  2. #include <string>
  3. #include <list>
  4. #include <map>
  5. #include <vector>
  6. #include <utility>
  7. #include <iomanip> //控制格式输出的,
  8. using namespace std;
  9. int main(int argc,char **argv)
  10. {
  11.     map<string,int> word_count;
  12.     string word;
  13.     while(cin>>word)
  14.     {
  15.         pair<map<string,int>::iterator,bool> ret=word_count.insert(make_pair(word,1));
  16.         if(!ret.second)
  17.             ++ret.first->second;
  18.     }
  19.     for(map<string,int>::iterator iter=word_count.begin();
  20.         iter!=word_count.end();++iter)
  21.     {
  22.         cout<<"string is :"<<setw(10)<<iter->first 
  23.             <<"    Count is :"<<iter->second<<endl;
  24.     }
  25.     return 0;
  26. }
posted on 2008-11-29 09:57  曲仁岗  阅读(177)  评论(0编辑  收藏  举报