Pagini recente » Cod sursa (job #2055441) | Cod sursa (job #2811842) | Cod sursa (job #2111789) | Cod sursa (job #1933862) | Cod sursa (job #1778667)
#include <iostream>
#include <fstream>
#include <map>
using namespace std;
main() {
ifstream cin("elmaj.in");
ofstream cout("elamj.out");
int n, maj = -1;
cin>>n;
map <int, int> h;
for (int i = 0; i < n; i++) {
int x;
cin>>x;
if (h.find(x) == h.end()) {
h[x] = 1;
} else {
h[x] = h[x] + 1;
}
if (h[x] > n/2) {
maj = x;
}
}
if (maj > -1) {
cout<<maj<<" "<<h[maj];
} else {
cout<<-1;
}
}