Cod sursa(job #2397865)
Utilizator | Data | 4 aprilie 2019 20:23:53 | |
---|---|---|---|
Problema | Elementul majoritar | Scor | 100 |
Compilator | cpp-64 | Status | done |
Runda | Arhiva educationala | Marime | 0.54 kb |
#include <iostream>
#include <fstream>
#include <unordered_map>
using namespace std;
ifstream fin("elmaj.in");
ofstream fout("elmaj.out");
#define For(i, a, b) for(i = (a); i <= (b); i++)
int n;
unordered_map<int, int> h;
unordered_map<int, int>::iterator it;
int main(){
int i, x, nr;
fin >> n;
For(i, 1, n){
fin >> x;
h[x]++;
}
nr = n / 2 + 1;
for(it = h.begin(); it != h.end(); it++)
if(it->second >= nr){
fout << it->first << ' ' << it->second;
break;
}
if(it == h.end()) fout << -1;
}