Advertisement
Ermolaxe

Map #1(6)

Jul 8th, 2015
229
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.17 KB | None | 0 0
  1. #include <fstream>
  2. #include <iostream>
  3. #include <algorithm>
  4. #include <string>
  5. #include <map>
  6.  
  7. using namespace std;
  8.  
  9. ifstream fin("input.txt");
  10. ofstream fout("output.txt");
  11.  
  12. bool isWord(string tmp)
  13. {
  14.                 if (isalpha(tmp[0])) return true;
  15.                 else return false;
  16. }
  17.  
  18. int main()
  19. {
  20.         int count=0;
  21.         cout << "Enter count: ";
  22.         cin >> count;
  23.         map <string, int> dict;
  24.         string tmp;
  25.         while (fin >> tmp)
  26.         {
  27.                 if (isWord(tmp))
  28.                 {
  29.                         if (dict.count(tmp)==0)
  30.                         {
  31.                                 dict.insert(pair<string,int>(tmp,1));
  32.                         }
  33.                         else
  34.                         {
  35.                                 dict.at(tmp)++;
  36.                         }
  37.                 }
  38.         }
  39.  
  40.         for (map<string, int>::iterator iter=dict.begin();iter!=dict.end();iter++)
  41.             fout << iter->first << "-" << iter->second << endl;
  42.         fout << "\\\\\\\\\\\\"<< endl;
  43.  
  44.         for (map<string, int>::iterator it=dict.begin();it!=dict.end();it++)
  45.                 if (it->second == count) fout << it->first << endl;
  46. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement