Advertisement
Sanlover

Untitled

Dec 22nd, 2021
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.83 KB | None | 0 0
  1. #include <fstream>
  2. #include <iostream>
  3. #include <Windows.h>
  4. #include <string>
  5. #include <map>
  6. #include <algorithm>
  7. using namespace std;
  8.  
  9. bool comparator(const pair<string, size_t>& first, const pair<string, size_t>& second)
  10. {
  11. return first.second != second.second ? first.second < second.second : first.first < second.first;
  12. };
  13.  
  14. int main()
  15. {
  16. SetConsoleOutputCP(1251);
  17. SetConsoleCP(1251);
  18. ifstream input("input.txt");
  19. if (!input.is_open())
  20. {
  21. cout << "File not found";
  22. return 0;
  23. }
  24. map<string, size_t> wordRepeats;
  25. while (input.good())
  26. {
  27. string tmp;
  28. getline(input, tmp);
  29. wordRepeats[tmp]++;
  30. }
  31. sort(wordRepeats.begin(), wordRepeats.end(), comparator);
  32. for (auto it = wordRepeats.cbegin(); it != wordRepeats.cend(); ++it)
  33. {
  34. std::cout << it->first << " " << it->second << "\n";
  35. }
  36. return 0;
  37. }
  38.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement