Cod sursa(job #2663439)
Utilizator | Data | 26 octombrie 2020 13:24:50 | |
---|---|---|---|
Problema | Elementul majoritar | Scor | 100 |
Compilator | cpp-64 | Status | done |
Runda | Arhiva educationala | Marime | 0.47 kb |
#include <bits/stdc++.h>
using namespace std;
ifstream f("elmaj.in");
ofstream g("elmaj.out");
int main()
{
int n;
unordered_map<int,int> M;
f>>n;
for(int i=1; i<=n; i++)
{
int x;
f>>x;
M[x]++;
}
for(unordered_map<int,int>::iterator i=M.begin(); i!=M.end(); i++)
if(i->second>n/2)
{
g<<i->first<<' '<<i->second;
return 0;
}
g<<-1;
return 0;
}