Cod sursa(job #1051611)
Utilizator | Radu Stanescu stanescu.radu | Data | 10 decembrie 2013 12:28:44 |
---|---|---|---|
Problema | Elementul majoritar | Scor | 0 |
Compilator | cpp | Status | done |
Runda | Arhiva educationala | Marime | 0.52 kb |
#include<fstream>
#include<unordered_map>
using namespace std;
ifstream f ("elmaj.in");
ofstream g("elmaj.out");
unordered_map <int,int> map;
unordered_map <int,int> :: iterator l;
int n,i,x;
int main ()
{
f >> n;
for (i = 1; i <= n; i++)
{
f >> x;
if (map.find(x)==map.end())
map.insert (make_pair(x,1);
else
map[x]++;
}
for (l = map.begin(); l <= map.end(); l ++)
if ((*l).second == (map.size())/2)
{
g<<(*l).first;
break;
}
f.close();
g.close();
return 0;
}