Cod sursa(job #2220536)
Utilizator | Data | 12 iulie 2018 00:59:04 | |
---|---|---|---|
Problema | Elementul majoritar | Scor | 90 |
Compilator | cpp | Status | done |
Runda | Arhiva educationala | Marime | 0.49 kb |
#include <fstream>
#include <map>
using namespace std;
ifstream cin("elmaj.in");
ofstream cout("elmaj.out");
int main()
{
map<int, int> m;
int n, x;
cin >> n;
int max = n/2 + 1;
int el = -1;
for(int i = 0; i < n; i++)
{
cin >> x;
m[x]++;
if(m[x] >= max)
{
max = m[x];
el = x;
}
}
if(el != -1)
cout << el << " " << m[el];
else
cout << -1;
}