Cod sursa(job #1658771)
| Utilizator | Data | 21 martie 2016 19:42:34 | |
|---|---|---|---|
| Problema | Elementul majoritar | Scor | 80 |
| Compilator | cpp | Status | done |
| Runda | Arhiva educationala | Marime | 0.51 kb |
#include <iostream>
#include <fstream>
using namespace std;
ifstream in("elmaj.in");
ofstream out("elmaj.out");
long long v[99999999],n,el,ct,nr,i,j;
int main()
{
in>>n;
nr=(n/2)+1;
for(i=1;i<=n;i++)
in>>v[i];
for(i=1;i<=n;i++){
ct = 1;
for(j=i+1;j<=n;j++)
if(v[i]==v[j])
ct++;
if(ct>=nr){
out << v[i] << " " << ct;
return 0;
}
}
out << "-1";
return 0;
}
