Cod sursa(job #2002617)
| Utilizator | Data | 20 iulie 2017 14:10:33 | |
|---|---|---|---|
| Problema | Elementul majoritar | Scor | 0 |
| Compilator | cpp | Status | done |
| Runda | Arhiva educationala | Marime | 0.55 kb |
#include <cstdio>
#include <map>
using namespace std;
map <int, int> nr;
map<int,int>::iterator it;
int main ()
{
FILE *f=fopen("majoritar.in","r");
FILE *g=fopen("majoritar.out","w");
int n,i,x,ok=0;
fscanf(f,"%d",&n);
for(i=0;i<n;i++)
{
fscanf(f,"%d",&x);
nr[x]++;
}
for(it = nr.begin();it!=nr.end();++it)
{
if(it->second>=(n/2)+1)
{
fprintf(g,"%d %d",it->first, it->second);
ok=1;
break;
}
}
if(ok==0)
fprintf(g,"-1");
return 0;
}
