Cod sursa(job #2195994)
Utilizator | Data | 17 aprilie 2018 23:41:37 | |
---|---|---|---|
Problema | Elementul majoritar | Scor | 100 |
Compilator | cpp | Status | done |
Runda | Arhiva educationala | Marime | 0.44 kb |
#include <iostream>
#include <fstream>
using namespace std;
ifstream fin("elmaj.in");
ofstream fout("elmaj.out");
const int nmax = 1000005;
int main()
{
int n, v[nmax], vvmax=0;
long long c, vv[nmax];
fin>>n;
for(int i=1; i<=n; ++i) {
fin>>v[i];
vv[v[i]]++;
if(vv[v[i]]>vvmax) {
c=v[i];
vvmax=vv[v[i]];
}
}
fout<<c<<' '<<vvmax;
return 0;
}