Pagini recente » Cod sursa (job #893310) | Cod sursa (job #398917) | Cod sursa (job #1045323) | Cod sursa (job #1973782) | Cod sursa (job #674356)
Cod sursa(job #674356)
#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;
return 0;
}
hhash[cheie].push_back(make_pair(x,1));
if(hhash[cheie][0].second>=(aux/2+1))
return hhash[cheie][i].second;
return 0;
}
int main()
{
int ok=0;int memo_nr,memo_fr;
ifstream in("elmaj.in");
ofstream out("elmaj.out");
in>>N;aux=N;
while(N--)
{
in>>numar;
aux2=operare(numar);
if(aux2>=(aux/2+1))
{
memo_nr=numar;
memo_fr=aux2;
ok=1;
}
}
if(ok==0)
out<<"-1";
else
out<<memo_nr<<" "<<memo_fr;
return 0;
}