Advertisement
Solingen

main.cpp

Nov 1st, 2024
20
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.16 KB | None | 0 0
  1. #include <iostream>
  2. #include <fstream>
  3. #include <map>
  4. #include <cstring>
  5. using std::cout;
  6. using std::endl;
  7. using std::ifstream;
  8. using std::map;
  9. #include "string.h"
  10.  
  11. int main(int argc, char* argv[])
  12. {
  13.     if (argc != 2)
  14.     {
  15.         cout << "Usage: " << argv[0] << " filename" << endl;
  16.         return 1;
  17.     }
  18.    
  19.     char* filename = argv[1];
  20.    
  21.     ifstream ff(filename);
  22.    
  23.     if (ff.fail())
  24.     {
  25.         cout << "File " << filename << " doesn't exists!\n";
  26.         return 2;
  27.     }
  28.    
  29.    
  30.     std::map<String, int> m;
  31.    
  32.     while (!ff.eof())
  33.     {
  34.         String s;
  35.         ff >> s;
  36.        
  37.         WordIterator iter = s.split(" \t\n\"+-*/%=><\\;:.!?(){}[]");
  38.        
  39.         if (iter.getCount())
  40.         {
  41.             do
  42.             {
  43.                 String w = iter.getCurrent();
  44.                 if (m.count(w))
  45.                     m[w]++;
  46.                 else
  47.                     m[w] = 1;
  48.             }
  49.             while (iter.moveNext());
  50.         }
  51.          
  52.     }
  53.    
  54.     for(auto iter=m.begin(); iter != m.end(); iter++)
  55.     {
  56.        cout << "!" << iter->first.str <<" : "<<  iter->second << endl;
  57.     }
  58. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement