Pagini recente » Cod sursa (job #832667) | Cod sursa (job #1204588) | Cod sursa (job #2744952) | Cod sursa (job #2819422) | Cod sursa (job #674349)
Cod sursa(job #674349)
#include<stdio.h>
#include<vector>
#define prim 123457
using namespace std;
vector<pair<int,int> >hhash[123460];
int N,numar,aux,aux2;
int operare(int x)
{
int cheie=x%prim,i;
for(i=0;i<hhash[cheie].size();i++)
if(hhash[cheie][i].first==x)
{
hhash[cheie][i].second++;
if(hhash[cheie][i].second>=(aux/2+1))
return hhash[cheie][i].second;
else
return 0;
}
hhash[cheie].push_back(make_pair(x,1));
if(hhash[cheie][0].second>=(aux/2+1))
return hhash[cheie][i].second;
else
return 0;
return -1;
}
int main()
{
int ok=0;
freopen("elmaj.in","r",stdin);
freopen("elmaj.out","w",stdout);
scanf("%d",&N);aux=N;
while(N--)
{
scanf("%d",&numar);
aux2=operare(numar);
if(aux2>=(aux/2+1))
{
printf("%d %d\n",numar,aux2);ok=1;
break;
}
}
if(ok==0)
printf("-1\n");
return 0;
}