Cod sursa(job #2251562)
Utilizator | Data | 1 octombrie 2018 19:01:00 | |
---|---|---|---|
Problema | Elementul majoritar | Scor | 100 |
Compilator | cpp | Status | done |
Runda | Arhiva educationala | Marime | 0.38 kb |
#include<bits/stdc++.h>
using namespace std;
ifstream f("elmaj.in");
ofstream g("elmaj.out");
unordered_map<int,int>myMap;
int n;
int main()
{
f>>n;
for(int i=1;i<=n;++i)
{
int x;
f>>x;
myMap[x]++;
}
for(auto i: myMap)
{
if(i.second>=n/2+1)
{
g<<i.first<<' '<<i.second;
}
}
}