Cod sursa(job #1051613)
Utilizator | FMI Florescu Vlad - Adrian vlad.florescu94 | Data | 10 decembrie 2013 12:31:16 |
---|---|---|---|
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 f("elmaj.in");
ofstream g("elmaj.out");
int i,n,x;
bool ok;
unordered_map<int,int> trust;
int main()
{
f>>n;
for(i=1;i<=n;i++)
{
f>>x;
trust[x]++;
}
for(unordered_map<int,int>::iterator it=trust.begin();it!=trust.end();it++)
if(it->second>n/2)
{g<<it->first<<" "<<it->second;
ok=1;
}
if(!ok)
g<<-1;
f.close();g.close();
return 0;
}