Cod sursa(job #2554984)

Utilizator Alin_StanciuStanciu Alin Alin_Stanciu Data 23 februarie 2020 16:12:15
Problema Elementul majoritar Scor 90
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.54 kb
#include <iostream>
#include <fstream>
#include <map>

using namespace std;

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

int n;
map<int, int> M;

int main()
{
    fin >> n;
    for (int i = 1; i <= n; ++i)
    {
        int x;
        fin >> x;
        ++M[x];
    }
    bool gasit = false;
    for (auto x : M)
    {
        if (x.second >= n / 2 + 1)
        {
            gasit = true;
            fout << x.first << " " << x.second;
        }
    }
    if (!gasit)
        fout << -1;

    return 0;
}