Cod sursa(job #2799494)

Utilizator AlexTacuTacu Alexandru AlexTacu Data 13 noiembrie 2021 11:51:51
Problema Elementul majoritar Scor 90
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.8 kb
#include <bits/stdc++.h>

using namespace std;

ifstream in("elmaj.in");
ofstream out("elmaj.out");

map < int, int > m;

int n;

void prg()
{
    in>>n;
    for(int i=1; i<=n; i++)
    {
        int x;
        in>>x;
        ++m[x];
    }
    map<int, int>::iterator itr;
    for (const auto & i : m)
        if(i.second>=n/2+1)
        {
            out<<i.first<<' '<<i.second;
            return ;
        }
    out<<-1;
    return ;
}

int main()
{
    prg();
    in.close();
    out.close();
    return 0;
}

/*
#include <bits/stdc++.h>
using namespace std;
ifstream f("map.in"); ofstream g("map.out");
map <long long, int> m;
int main()
{   int n;
    f>>n;
    while(n--)
    {   long long x;
        f>>x; g<<++m[x]<<' ';
    }
    g.close(); return 0;
}
*/