Cod sursa(job #3289820)
Utilizator | Data | 28 martie 2025 17:04:59 | |
---|---|---|---|
Problema | Elementul majoritar | Scor | 10 |
Compilator | cpp-64 | Status | done |
Runda | Arhiva educationala | Marime | 0.46 kb |
#include <iostream>
#include <fstream>
using namespace std;
ifstream f("elmaj.in");
ofstream g("elmaj.out");
int ap=0, nr=-1;
int main()
{
int n, x;
f >> n;
for(int i=1; i<=n; i++)
{
f >> x;
if(x==nr)
ap++;
else
{
if(ap>0)
ap--;
else
ap=1, nr=x;
}
}
if(ap>=1)
g << nr << " " << n/2+ap;
return 0;
}