Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <fstream>
- #include <iostream>
- #include <Windows.h>
- #include <string>
- #include <map>
- #include <algorithm>
- using namespace std;
- bool comparator(const pair<string, size_t>& first, const pair<string, size_t>& second)
- {
- return first.second != second.second ? first.second < second.second : first.first < second.first;
- };
- int main()
- {
- SetConsoleOutputCP(1251);
- SetConsoleCP(1251);
- ifstream input("input.txt");
- if (!input.is_open())
- {
- cout << "File not found";
- return 0;
- }
- map<string, size_t> wordRepeats;
- while (input.good())
- {
- string tmp;
- getline(input, tmp);
- wordRepeats[tmp]++;
- }
- sort(wordRepeats.begin(), wordRepeats.end(), comparator);
- for (auto it = wordRepeats.cbegin(); it != wordRepeats.cend(); ++it)
- {
- std::cout << it->first << " " << it->second << "\n";
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement