Cod sursa(job #1434675)

Utilizator teoceltareconstantin teodor teoceltare Data 11 mai 2015 08:24:16
Problema Elementul majoritar Scor 100
Compilator cpp Status done
Runda Arhiva educationala Marime 0.43 kb
#include<iostream>
#include<fstream>
using namespace std;
ifstream fin("elmaj.in");
ofstream fout("elmaj.out");
int v[1000010];
int main()
{
    int x;
    int n,max1=0,nrmax;
    fin>>n;
    for(int a=1;a<=n;a++)
    {
        fin>>x;
        v[x]++;
        if(v[x]>max1)
        {
            max1=v[x];
            nrmax=x;
        }
    }
    if(max1>=n/2+1)
    {
        fout<<nrmax<<" "<<max1;
    }
}