Mai intai trebuie sa te autentifici.
Cod sursa(job #2220541)
Utilizator | Data | 12 iulie 2018 01:27:44 | |
---|---|---|---|
Problema | Elementul majoritar | Scor | 100 |
Compilator | cpp | Status | done |
Runda | Arhiva educationala | Marime | 0.51 kb |
#include <fstream>
#include <unordered_map>
using namespace std;
ifstream cin("elmaj.in");
ofstream cout("elmaj.out");
int main()
{
unordered_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;
}