Cod sursa(job #1665326)
Utilizator | Data | 26 martie 2016 20:36:34 | |
---|---|---|---|
Problema | Elementul majoritar | Scor | 100 |
Compilator | cpp | Status | done |
Runda | Arhiva educationala | Marime | 0.44 kb |
#include <fstream>
using namespace std;
ifstream f("elmaj.in");
ofstream g("elmaj.out");
const int Nmax = 1000005;
int ap[Nmax], n, Max, el;
int main()
{
f>>n;
int x;
Max = n/2;
while(n--)
{
f>>x;
ap[x]++;
if(ap[x] > Max)
{
Max = ap[x];
el = x;
}
}
if(ap[el] > n/2) g<<el<<' '<<ap[el]<<'\n';
else g<<-1<<'\n';
return 0;
}