Cod sursa(job #1050303)

Utilizator PsychoAlexAlexandru Buicescu PsychoAlex Data 8 decembrie 2013 14:38:33
Problema Elementul majoritar Scor 80
Compilator cpp Status done
Runda Arhiva educationala Marime 0.82 kb
#include <iostream>
#include <fstream>
#include <unordered_map>
//#include <map>

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

int n;
std::unordered_map<int, int> aparitii;
//std::map<long long, int> aparitii;

void citire()
{
    fin>>n;
    long long x;
    long long maxim = -1, indice;
    for(int i = 0; i < n; i++)
    {
        fin>>x;
        aparitii[x]++;
        if(aparitii[x] > maxim)
        {
            maxim = aparitii[x];
            indice = x;
        }
//        if(maxim >= n / 2 + 1)
//        {
//            break;
//        }
    }
    if(maxim >= n / 2 + 1)
    {
        fout<<indice<<' '<<maxim<<'\n';
    }
    else
    {
        fout<<-1<<'\n';
    }
}

void rezolvare()
{

}

int main()
{
    citire();
    rezolvare();
    return 0;
}