非专业程序员

  :: 首页 :: 博问 :: 闪存 :: 新随笔 :: 联系 :: 订阅 订阅 :: 管理 ::
  1. #include <iostream>
  2. #include <sstream>
  3. #include <string>
  4. #include <list>
  5. #include <map>
  6. #include <vector>
  7. #include <utility>
  8. #include <iomanip> //控制格式输出的,
  9. using namespace std;
  10. int main(int argc,char **argv)
  11. {
  12.     string line1="We were her pride of 10 she named us: ";
  13.     string line2="Benjamin, phoenix, the prodigal";
  14.     string line3="and perspicacious pacific suzanne";
  15.     string sentence=line1+' '+line2+' '+line3;
  16.     std::istringstream stream(sentence);
  17.     string word;
  18.     map<string,int> word_count;
  19.     while(stream>>word)
  20.         ++word_count[word];
  21.     int words=0;
  22.     for(map<string,int>::iterator iter=word_count.begin();
  23.         iter!=word_count.end();++iter)
  24.     {
  25.         words+=iter->second;
  26.     }
  27.     cout<<words<<endl;
  28.     return 0;
  29. }
posted on 2008-11-29 10:24  曲仁岗  阅读(144)  评论(0编辑  收藏  举报