Skip to content

Instantly share code, notes, and snippets.

@gtindo
Last active February 26, 2021 21:43
Show Gist options
  • Save gtindo/dbcd3683af2c3bbd0ca7f8c20479fcca to your computer and use it in GitHub Desktop.
Save gtindo/dbcd3683af2c3bbd0ca7f8c20479fcca to your computer and use it in GitHub Desktop.
occ.cpp
#include <bits/stdc++.h>
using namespace std;
int main(){
//freopen("input.txt", "r", stdin);
string word;
map<string, int> occ;
string max_w;
int max_occ = 0;
while(cin >> word){
if(occ.count(word)){
occ[word] += 1;
}else{
occ[word] = 1;
}
if(occ[word] > max_occ){
max_occ = occ[word];
max_w = word;
}
}
cout << max_w << endl;
cout << max_occ << endl;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment