Pagini recente » Cod sursa (job #2485845) | Cod sursa (job #1744944) | Cod sursa (job #200942) | Cod sursa (job #2163232) | Cod sursa (job #2080168)
#include <iostream>
#include <fstream>
using namespace std;
ifstream fin ("elmaj.in");
ofstream fout ("elmaj.out");
int main()
{
int a,b[1000],c,d=0,e=0,a1,max1=0,restrictie[1000];
fin>>a;
a1=a/2;
a1+=1;
if(a>=1 && a<=100000)
{
for(int i=0;i<a;++i)
{
fin>>restrictie[i];
if(restrictie[i]>=1 && restrictie[i]<=100000)
{
b[i]=restrictie[i];
}
}
for(int i=0;i<a;i++)
{
e=0;
c=b[i];
for(int j=0;j<a;j++)
{
if(b[j]==c)
{
e++;
}
}
if(e>=a1)
{
if(max1<e)
max1=e;
}
}
for(int i=0;i<a;++i)
{
e=0;
c=b[i];
for(int j=0;j<a;j++)
{
if(b[j]==c)
{
e++;
}
}
if(e==max1)
{
d=b[i];
}
}
if(max1!=0)
{
fout<<d<<" "<<max1;
}else{fout<<-1;}
}
return 0;
}