f0617.cpp
资源名称:c.rar [点击查看]
上传用户:puke2000
上传日期:2022-07-25
资源大小:912k
文件大小:1k
源码类别:

C#编程

开发平台:

Visual C++

  1. //=================================
  2. // f0617.cpp
  3. // 清点单词数
  4. //=================================
  5. #include<iostream>
  6. #include<fstream>
  7. #include<sstream>
  8. #include<vector>
  9. #include<map>
  10. using namespace std;
  11. typedef multimap<int,int> Mmap;
  12. //---------------------------------
  13. int main(){
  14.   ifstream in("abc.txt");
  15.   vector<string> abc;
  16.   // abc.reserve(1100);
  17.   Mmap nums;
  18.   int n=0;
  19.   for(string s; getline(in,s); ){
  20.     istringstream sin(s);
  21.     int num=0;
  22.     for(string t;  sin>>t; num++);
  23.     if(num){
  24.       nums.insert(Mmap::value_type(num, n++));
  25.       abc.push_back(s);
  26.     }
  27.   }
  28.   for(Mmap::iterator it=nums.begin(); it!=nums.end(); ++it)
  29.     cout<<abc[it->second]<<endl;
  30. }//=================================
  31.