Cod sursa(job #1672784)

Utilizator teosposibSposib Teodor Alexandru teosposib Data 3 aprilie 2016 03:05:11
Problema Elementul majoritar Scor 90
Compilator cpp Status done
Runda Arhiva educationala Marime 0.45 kb
#include <fstream>
#include<iostream>
#include<map>
using namespace std;
ifstream f("elmaj.in");
ofstream g("elmaj.out");
map<long,long> v;
map<long,long>::iterator it;

int main()
{long N,max=0,x,ind;
 f>>N;
 for(long i=1;i<=N;i++)
    {f>>x;
     it=v.find(x);
     if (it!= v.end()) v[x]++;
     else v[x]=1;
     if(v[x]>max) {max=v[x];ind=x;}}
 if(v[ind]<N/2) g<<-1;
 else g<<ind<<" "<<v[ind];
f.close();g.close();
    return 0;
}