Pagini recente » Cod sursa (job #40578) | Borderou de evaluare (job #2709098) | Borderou de evaluare (job #3147419) | Cod sursa (job #2796731) | Cod sursa (job #760579)
Cod sursa(job #760579)
#include <fstream>
using namespace std;
const int N=1000001;
ifstream fin("elmaj.in");
ofstream fout("elmaj.out");
int main()
{
int n,check,j,i,k=0,nrmax=0,imax=0,v[N],x,f[N];
fin>>n;
for(i=0;i<n;i++)
{
check=0;
fin>>x;
for(j=0;j<k;j++)
{
if(v[j]==x)
{
f[j]++;
check=1;
if (f[j]>=nrmax)
{
nrmax=f[j];
imax=j;
}
}
}
if ( !check)
{
f[k]=1;
v[k++]=x;
}
}
//x=0;
/* for(j=0;j<k;j++)
{
if(f[j]>x)
{
x=f[j];
imax=j;
}
}*/
if(nrmax>=n/2 +1)
fout<<v[imax]<<" "<<nrmax;
else
fout<<-1;
fin.close();
fout.close();
return 0;
}