Cod sursa(job #1083415)

Utilizator leontinLeontin leontin Data 15 ianuarie 2014 22:55:35
Problema Elementul majoritar Scor 100
Compilator cpp Status done
Runda Teme Pregatire ACM Unibuc 2013 Marime 0.42 kb
#include<iostream>
#include<fstream>
using namespace std;
#define max 400000000
long  a[max],n,x,maxx=0,elma;
ifstream f("elmaj.in");
ofstream g("elmaj.out");
int main()
{
    f>>n;
    int i;
    for(i=1;i<=n;i++)
    {
        f>>x;
        a[x]++;
        if(a[x]>maxx)
        {

         maxx=a[x];
         elma=x;
        }
    }
    if(maxx>n/2)
        g<<elma<<" "<<maxx;
    return 0;

}