Cod sursa(job #2562385)

Utilizator gabbie02Thomits Gabriel gabbie02 Data 29 februarie 2020 13:55:37
Problema Elementul majoritar Scor 50
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.43 kb
#include <fstream>
#include <map>

using namespace std;

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

void maj()
{
    map<unsigned int, unsigned int> ap;
    unsigned int n, x;
    fin >> n;
    n >>= 1;
    while(fin >> x){
        ap[x]++;
        if(ap[x] > n){
            fout << x << " " << ap[x];
            return;
        }
    }
    fout << -1;
}

int main()
{
    maj();
    return 0;
}