Cod sursa(job #1082546)

Utilizator andreeaghetuUNIBUC andreeaghetu andreeaghetu Data 14 ianuarie 2014 19:25:11
Problema Elementul majoritar Scor 100
Compilator cpp Status done
Runda Teme Pregatire ACM Unibuc 2013 Marime 0.53 kb
#include <fstream>
#include <unordered_map>
using namespace std;
ifstream in ("elmaj.in");
ofstream out ("elmaj.out");
 
int main()
{
    int N, x;
    in>>N;
    unordered_map <int, int> v;
    for (int i=0;i<N;++i)
    {
        in>>x;
        ++v[x];
    }
    int N_pe_doi=N/2;
    for (unordered_map <int, int>::iterator i=v.begin();i!=v.end();++i)
    {
        if (i->second>N_pe_doi)
        {
            out<<i->first<<" "<<i->second;
            return 0;
        }
    }
    out<<-1;
    return 0;
}