Pagini recente » Cod sursa (job #1294846) | Diferente pentru preoni-2006/runda-4/solutii intre reviziile 5 si 27 | Profil M@2Te4i | runda/listen_to_bfmw_while_solving | Cod sursa (job #2002617)
#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;
}