1 #include <stdio.h> 2 #include <string> 3 #include <iostream> 4 #include <fstream> 5 #include <iterator> 6 #include <vector> 7 #include <algorithm> 8 #include <map> 9 using namespace std; 10 map<string,int> map_meng; 11 12 void print(const pair<string,int> &r) 13 { 14 cout<<r.first<<" "<<r.second<<endl; 15 } 16 17 void record(const string &s) 18 { 19 map_meng[s]++; 20 } 21 bool gt10(const pair<string,int> &r) 22 { 23 return r.second>10; 24 } 25 bool gt9(const pair<string,int> &r) 26 { 27 return r.second>9; 28 } 29 int main() 30 { 31 32 ifstream is("1"); 33 34 istream_iterator<string> ii(is); 35 istream_iterator<string> eos; 36 37 for_each(ii,eos,record); 38 // for_each(map_meng.begin(),map_meng.end(),print); 39 40 map<string,int>::iterator p; 41 p=find_if(map_meng.begin(),map_meng.end(),gt10); 42 cout<<p->first<<" "<<p->second<<endl; 43 44 cout<<count_if(map_meng.begin(),map_meng.end(),gt9)<<endl; 45 46 return 0; 47 }