Skip to content

Instantly share code, notes, and snippets.

@nicolekorch
Created December 14, 2025 11:07
Show Gist options
  • Select an option

  • Save nicolekorch/42b7872b9211d64be3ab48407286a9f8 to your computer and use it in GitHub Desktop.

Select an option

Save nicolekorch/42b7872b9211d64be3ab48407286a9f8 to your computer and use it in GitHub Desktop.
#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;
}
@nicolekorch
Copy link
Author

2

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment