Created
December 14, 2025 11:07
-
-
Save nicolekorch/42b7872b9211d64be3ab48407286a9f8 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> | |
| #include <cctype> | |
| using namespace std; | |
| int main() { | |
| ifstream in("input.txt"); | |
| ofstream out("output.txt"); | |
| map<string, int> freq; | |
| string word; | |
| while (in >> word) { | |
| string w; | |
| for (char c : word) { | |
| if (isalpha((unsigned char)c)) | |
| w += tolower(c); | |
| } | |
| if (!w.empty()) | |
| freq[w]++; | |
| } | |
| string maxWord; | |
| int maxCount = 0; | |
| for (auto &p : freq) { | |
| cout << p.first << " " << p.second << endl; | |
| out << p.first << " " << p.second << endl; | |
| if (p.second > maxCount) { | |
| maxCount = p.second; | |
| maxWord = p.first; | |
| } | |
| } | |
| cout << maxWord << " " << maxCount << endl; | |
| out << maxWord << " " << maxCount << endl; | |
| return 0; | |
| } |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
2