Cod sursa(job #1061715)
| Utilizator | Data | 20 decembrie 2013 10:39:08 | |
|---|---|---|---|
| Problema | Elementul majoritar | Scor | 100 |
| Compilator | cpp | Status | done |
| Runda | Teme Pregatire ACM Unibuc 2013 | 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;
}
