eolymp
bolt
Try our new interface for solving problems
Problems

Maximum Word Frequency

published at 5/5/15, 8:06:44 pm

Если одно слово меньше другого то оно стоит перед ним в лексикографическом порядке!

published at 1/11/24, 2:42:22 pm

include <bits/stdc++.h>

define ll long long

define ld long double

using namespace std; int main(){

ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
ll n, mx = -99999999, m;
cin>>n;
multiset<string>s;
vector<string>v;
for(ll i = 0; i<n; i++){
    string k;
    cin>>k;
    s.insert(k);
    m = s.count(k);
    mx = max(mx, m);
}
for(auto i = s.begin(); i!=s.end(); i++){
    if(s.count(*i) == mx){
        v.push_back(*i);
    }
}
cout<<v[v.size()-1]<<' '<<mx;

} //TECHNOBLADE NEVER DIE

published at 1/12/24, 4:34:47 pm
#include <bits/stdc++.h>
using namespace std;
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    multiset<string> mst;
    int m, n = 0;
    string s, k;
    cin>>m;
    for(int i = 0; i < m; i++){
        cin>>s;
        mst.insert(s);
    }
    for(auto x : mst){
        if(mst.count(x) >= n){
            n = mst.count(x);
            k = x;
        }
    }
    cout<<k<<" "<<n<<endl;
    return 0;
}

Made in C++ using multiset.

published at 1/13/24, 7:49:45 pm

include <bits/stdc++.h>

define ll long long

define pb push_back

define in insert

using namespace std; int main() { ll n; cin >> n; set<string> s; vector<string> v; for(ll i = 0 ;i < n;i++) { string m; cin >> m; s.in(m); v.pb(m); } vector<pair<int,string>> res; for(string i : s) { int k = 0; for(string j : v) { if(i == j) k++; } pair <int,string> p; p.first = k; p.second = i; res.pb(p); } pair<int,string> max = *max_element(res.begin(),res.end()); cout << max.second << " " << max.first; }

published at 4/4/24, 7:44:14 pm

include <bits/stdc++.h>

using namespace std;

string BigString(string s,string x){ int n=s.length();

for(int i=0;i<n;i++){
    if(s[i]>x[i]){
        return s;
    }
    if(x[i]>s[i]){
        return x;
    }
}
return x;

}

int main() { int n,i,j,k=0,kmax=0; cin>>n; string s=" "; string Slist[n];

for(i=0;i<n;i++)
cin>>Slist[i];


for(i=0;i<n;i++){
    k=0;
    for(j=0;j<n;j++){
        if(Slist[i]==Slist[j]){
            k++;
        }
    }
    if(k>kmax){
        s=Slist[i];
        kmax=k;
    }
    if(k==kmax){
        if(s.length()<Slist[i].length()){
            s=Slist[i];
        }
        if(s.length()==Slist[i].length()){
         s=BigString(s,Slist[i]);   
        }
    }
}

cout<<s<<' '<<kmax;
return 0;

}

published at 4/8/24, 5:32:21 pm

include <bits/stdc++.h>

using namespace std; int main() { int n; cin>>n; map<string,int>m; string s; for(int i=0;i<n;i++) { cin>>s; m[s]++; } pair<string,int>p={"",0}; for(auto& z : m) { if(z.second>p.second || (z.second==p.second && z.first>p.first)) p=z; } cout<<p.first<<" "<<p.second; }