Created
December 17, 2025 19:29
-
-
Save XoLinA/bc9bf7de15422a00e57b6d34ede92ee6 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #include <iostream> | |
| #include <fstream> | |
| #include <map> | |
| #include <string> | |
| using namespace std; | |
| int main() | |
| { | |
| ifstream inFile("input.txt"); | |
| ofstream outFile("output.txt"); | |
| if (!inFile.is_open()) | |
| { | |
| cout << "File not found\n"; | |
| return 1; | |
| } | |
| map<string, int> freq; | |
| string word; | |
| while (inFile >> word) | |
| { | |
| freq[word]++; | |
| } | |
| cout << "Result:\n"; | |
| outFile << "Result:\n"; | |
| map<string, int>::iterator it; | |
| for (it = freq.begin(); it != freq.end(); it++) | |
| { | |
| cout << (*it).first << " : " << (*it).second << endl; | |
| outFile << (*it).first << " : " << (*it).second << endl; | |
| } | |
| string maxWord = ""; | |
| int maxCount = 0; | |
| for (it = freq.begin(); it != freq.end(); it++) | |
| { | |
| if ((*it).second > maxCount) | |
| { | |
| maxCount = (*it).second; | |
| maxWord = (*it).first; | |
| } | |
| } | |
| cout << "\Best word: " << maxWord << " count: " << maxCount << endl; | |
| outFile << "\nBest word: " << maxWord << " count: " << maxCount << endl; | |
| inFile.close(); | |
| outFile.close(); | |
| return 0; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment