Cod sursa(job #2150543)
Utilizator | Bogdan Filote fylot3 | Data | 3 martie 2018 17:08:19 |
---|---|---|---|
Problema | Elementul majoritar | Scor | 0 |
Compilator | cpp | Status | done |
Runda | Arhiva educationala | Marime | 0.45 kb |
#include <fstream>
#include <unordered_map>
int main(void) {
int N, Element;
std::ifstream fin("elmaj.in");
fin >> N;
std::unordered_map<int, size_t> MapCount;
for (auto i = 0; i < N; i++) {
fin >> Element;
MapCount[Element]++;
}
std::ofstream fout("elmaj.out");
for (auto &entry : MapCount) {
if (entry.second >= N / 2 + 1) {
fout << entry.first << " " << entry.second;
exit(0);
}
}
fout << -1;
return 0;
}