Cod sursa(job #2788034)

Utilizator enedumitruene dumitru enedumitru Data 24 octombrie 2021 18:53:45
Problema Elementul majoritar Scor 80
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.43 kb
#include <bits/stdc++.h>
using namespace std;
ifstream f("elmaj.in"); ofstream g("elmaj.out");
int n;
map < int , int > m;
int main()
{   f>>n;
    for(int x,i=1;i<=n;i++) {f>>x; ++m[x];}
    map<int, int>::iterator it=m.begin(),sf=m.end();
    for(; it!= m.end(); ++it)
        if((*it).second>n/2)
            {g<<(*it).first<<' '<<(*it).second; g.close(); f.close(); return 0;}
    g<<-1; g.close(); f.close(); return 0;
}