Cod sursa(job #1061131)

Utilizator Iustin_BulimarFMI Iustin Bulimar Iustin_Bulimar Data 19 decembrie 2013 11:28:12
Problema Elementul majoritar Scor 100
Compilator cpp Status done
Runda Teme Pregatire ACM Unibuc 2013 Marime 0.49 kb
#include <fstream>
#include <unordered_map>
using namespace std;
ifstream cin("elmaj.in");
ofstream cout("elmaj.out");

int n, i, x, a, b;
unordered_map<int, int> h;
unordered_map<int, int>::iterator it;

int main()
{
    cin>>n;
    for(i=1; i<=n; i++)
    {
        cin>>x;
        h[x]++;
    }
    for(it=h.begin(); it!=h.end(); it++)
        if(it->second>b)
        {
            a=it->first;
            b=it->second;
        }
    cout<<a<<" "<<b;
    return 0;
}