Cod sursa(job #1018352)

Utilizator Johny_Depp22Johnny Depp Johny_Depp22 Data 29 octombrie 2013 14:23:07
Problema Elementul majoritar Scor 100
Compilator cpp Status done
Runda Arhiva educationala Marime 0.39 kb
#include<iostream>
#include<fstream>
using namespace std;

ifstream f("elmaj.in");
ofstream g("elmaj.out");

int n, x, maxi=0, maxix, a[1000010];

int main()
{
    f>>n;
    for(int i=1; i <=n; ++i)
    {
        f>>x; a[x]++;
        if(a[x]>maxi)
        {
            maxi=a[x]; maxix=x;
        }
    }
    g<<maxix <<' '<<maxi;
    f.close(); g.close();
    return 0;
}