Cod sursa(job #1168392)
| Utilizator | Data | 8 aprilie 2014 11:11:50 | |
|---|---|---|---|
| Problema | Elementul majoritar | Scor | 90 |
| Compilator | cpp | Status | done |
| Runda | Arhiva educationala | Marime | 0.55 kb |
#include<fstream>
#include<algorithm>
#include<map>
using namespace std;
ifstream f("elmaj.in");
ofstream g("elmaj.out");
map<unsigned,unsigned>has;
map<unsigned,unsigned>::iterator it;
int T,n,i,m,x,elmaj=-1,nrap;
int main()
{
f>>n;
for(i=1;i<=n;i++)
{
f>>x;
has[x]++;
if(has[x]>n/2)
{
nrap=has[x];
elmaj=x;
}
}
if(elmaj==-1)g<<-1;
else g<<elmaj<<" "<<nrap;
return 0;
}
