Pagini recente » Cod sursa (job #1846779) | Cod sursa (job #174772) | Cod sursa (job #357543) | Cod sursa (job #2382869) | Cod sursa (job #674345)
Cod sursa(job #674345)
#include<stdio.h>
#include<vector>
#define prim 123457
using namespace std;
vector<pair<long unsigned,long unsigned> >hhash[123460];
long unsigned N,numar,aux,aux2;
long unsigned operare(long unsigned x)
{
long unsigned 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 1;
}
hhash[cheie].push_back(make_pair(x,1));
return 0;
}
int main()
{
freopen("elmaj.in","r",stdin);
freopen("elmaj.out","w",stdout);
scanf("%lu",&N);aux=N;
while(N--)
{
scanf("%lu",&numar);
aux2=operare(numar);
if(aux2>=(aux/2+1))
{
printf("%lu %lu\n",numar,aux2);
return 0;
}
}
printf("-1\n");
return 0;
}