Cod sursa(job #1608313)
| Utilizator | Data | 21 februarie 2016 23:20:22 | |
|---|---|---|---|
| Problema | Elementul majoritar | Scor | 90 |
| Compilator | cpp | Status | done |
| Runda | Arhiva educationala | Marime | 0.52 kb |
#include <cstdio>
#include <map>
using namespace std;
map<long long,int> x;
int n,aux,i;
int main()
{
freopen("elmaj.in","r",stdin);
freopen("elmaj.out","w",stdout);
scanf("%d\n",&n);
for(i=1;i<=n;i++){
scanf("%d",&aux);
x[aux]++;
}
for(map<long long,int>::iterator it=x.begin();it!=x.end();++it)
if(it->second>=n/2+1){
printf("%d ",it->first);
printf("%d ",it->second);
return 0;
}
printf("-1");
return 0;
}
