Cod sursa(job #1238565)
Utilizator | Data | 7 octombrie 2014 10:43:34 | |
---|---|---|---|
Problema | Elementul majoritar | Scor | 10 |
Compilator | cpp | Status | done |
Runda | Arhiva educationala | Marime | 0.49 kb |
#include <iostream>
#include <fstream>
using namespace std;
int a[86]={0};
int main()
{
ifstream f("elmaj.in");
ofstream g("elmaj.out");
int n,ok=1,mx=0,x;
f >> n;
f >> x;
mx=x;
for(int i=1;i<=n-1;++i)
{
f >> x;
if(ok==0)
{
mx=x;
}
if(x==mx)
{
++ok;
}
else --ok;
}
if(ok>=0) g << mx <<" " << (n/2)+ok;
else g << "-1";
return 0;
}