Cod sursa(job #1239538)
| Utilizator | Data | 9 octombrie 2014 10:31:24 | |
|---|---|---|---|
| Problema | Elementul majoritar | Scor | 10 |
| Compilator | cpp | Status | done |
| Runda | Arhiva educationala | Marime | 0.5 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=0,mx=0,x;
f >> n;
for(int i=1;i<=n;++i)
{
f >> x;
if(ok==0)
{
mx=x;
}
if(x==mx)
{
++ok;
}
else --ok;
cout << ok << " ";
}
if(ok>0) g << mx <<" " << (n/2)+(ok+1)/2;
else g << "-1";
return 0;
}
