Pagini recente » Cod sursa (job #2011717) | Cod sursa (job #2271752) | Cod sursa (job #762831) | Cod sursa (job #2161818) | Cod sursa (job #674350)
Cod sursa(job #674350)
#include<stdio.h>
#include<vector>
#include <fstream>
#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;
ifstream in("elmaj.in");
ofstream out("elmaj.out");
in>>N;aux=N;
while(N--)
{
in>>numar;
aux2=operare(numar);
if(aux2>=(aux/2+1))
{
out<<numar<<' '<<aux2;ok=1;
break;
}
}
if(ok==0)
out<<"-1";
return 0;
}