Cod sursa(job #2680929)
Utilizator | Data | 4 decembrie 2020 17:15:32 | |
---|---|---|---|
Problema | Elementul majoritar | Scor | 20 |
Compilator | cpp-64 | Status | done |
Runda | Arhiva educationala | Marime | 0.56 kb |
#include <iostream>
#include <fstream>
using namespace std;
ifstream fin ("elmaj.in");
ofstream fout ("elmaj.out");
int n, x, c, aux;
void read()
{
fin >> n;
fin >> x;
aux=x;
c=1;
for (int i=1;i<n;++i)
{
fin >> x;
if (c>0)
{
if (x!=aux)
c--;
else
c++;
}
else
{
aux=x;
c=1;
}
}
fout << aux << " " << (n-c)/2+c;
}
int main()
{
read();
return 0;
}