Pagini recente » Cod sursa (job #2149143) | Cod sursa (job #1465246) | Cod sursa (job #2281879) | Cod sursa (job #1953668) | Cod sursa (job #696846)
Cod sursa(job #696846)
#include<fstream>
using namespace std;
struct {long long e; long f;} x[1000000],aux;
int main()
{long n,i,j,l,ok;
long long nr;
ifstream g("elmaj.in");
g>>n;
g>>nr; l=0;
x[l].e=nr;
x[l].f=1;
for(i=1;i<n;i++)
{g>>nr; ok=1;
for(j=0;((j<=l)&&(ok==1));j++)
if(nr==x[j].e)
{x[j].f++;
ok++;}
if(ok==1)
{l++;
x[l].e=nr;
x[l].f=1;}
}
aux=x[0];
for(i=1;i<=l;i++)
if(aux.f<x[i].f)
if(x[i].f>=n/2+1)
aux=x[i];
ofstream t("elmaj.out");
if(aux.f>=n/2+1)
t<<aux.e<<" "<<aux.f;
else
t<<-1;
g.close();
t.close();
return 0;
}