Pagini recente » Cod sursa (job #1972861) | Cod sursa (job #439644) | Cod sursa (job #3216216) | Cod sursa (job #2966112) | Cod sursa (job #2659185)
#include <iostream>
#include <fstream>
#include <unordered_map>
using namespace std;
int main() {
ifstream f("elmaj.in");
ofstream g("elmaj.out");
int n;
f >> n;
int x;
int result = -1;
unordered_map<int, int> frecuency;
for(int i = 0; i < n; i++) {
f >> x;
if (frecuency.find(x) == frecuency.end()) {
frecuency.emplace(x, 1);
} else {
frecuency.at(x)++;
}
if (result == -1 && frecuency.at(x) == n/2 +1) {
result = x;
}
}
if (result != -1) {
g << result << " " << frecuency[result] << endl;
} else {
g << "-1" << endl;
}
return 0;
}