Cod sursa(job #2797157)
Utilizator | Data | 9 noiembrie 2021 13:43:41 | |
---|---|---|---|
Problema | Elementul majoritar | Scor | 80 |
Compilator | cpp-64 | Status | done |
Runda | Arhiva educationala | Marime | 0.42 kb |
#include <bits/stdc++.h>
using namespace std;
ifstream f("elmaj.in"); ofstream g("elmaj.out");
int n,v[1000001];
int main()
{ f>>n;
for(int i=1;i<=n;i++) f>>v[i];
for(int i=1;i<=n;i++)
{
int nr=0;
for(int j=1;j<=n;j++)
if(v[i]==v[j])nr++;
if(nr>n/2) {g<<v[i]<<' '<<nr;g.close(); f.close(); return 0;}
}
g<<"-1";
g.close(); f.close(); return 0;
}