Cod sursa(job #633982)
Utilizator | andreycurent an_drey_curent | Data | 15 noiembrie 2011 11:27:03 |
---|---|---|---|
Problema | Elementul majoritar | Scor | 50 |
Compilator | cpp | Status | done |
Runda | Arhiva educationala | Marime | 0.42 kb |
#include<iostream>
#include<fstream>
#include<vector>
using namespace std;
vector<long unsigned>v;
long unsigned N;
ifstream f("elmaj.in");
ofstream g("elmaj.out");
int main()
{
long unsigned i,x;
f>>N;
for(i=1;i<=1000002;i++)
v.push_back(0);
for(i=1;i<=N;i++)
{
f>>x;
v[x]++;
if(v[x]>N/2)
{
g<<x<<' '<<v[x];
break;
}
}
if(i>N)
g<<-1;
f.close();
g.close();
return 0;
}