Seal_of_approval

PrMap1

Jul 6th, 2015
230
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.62 KB | None | 0 0
  1. #include <fstream>
  2. #include <map>
  3. #include <string>
  4. #include <iostream>
  5.  
  6. using namespace std;
  7.  
  8. int main()
  9. {
  10.     ifstream in ("/Users/masha/Documents/PrMap1/PrMap1/input");
  11.    
  12.     map<string, int> m;
  13.     string s;
  14.     while (in >> s)
  15.     {
  16.         if (isdigit(s[0]) || (s.length()!= 1 && isdigit(s[1])))
  17.         {
  18.             map<string,int>::iterator it = m.find(s);
  19.             if (it != m.end()) m[s]++;
  20.             else m[s] = 1;
  21.         }
  22.     }
  23.    
  24.     for (map<string, int>::const_iterator it = m.begin(); it != m.end(); ++it)
  25.         cout << it->first << ": " << it->second << endl;
  26.    
  27.     return 0;
  28. }
Advertisement
Add Comment
Please, Sign In to add comment