Cod sursa(job #2213672)
Utilizator | Data | 16 iunie 2018 20:36:35 | |
---|---|---|---|
Problema | Elementul majoritar | Scor | 100 |
Compilator | cpp | Status | done |
Runda | Arhiva educationala | Marime | 0.34 kb |
#include <fstream>
#include <unordered_map>
using namespace std;
ifstream f("elmaj.in");
ofstream g("elmaj.out");
unordered_map <int, int> H;
int main()
{
int n;
f >> n;
for(int i = 1; i <= n; i++)
{
int x;
f >> x;
H[x]++;
}
for(auto& i: H)
if(i.second > n / 2)
{
g << i.first << " " << i.second;
return 0;
}
g << -1;
}