Pagini recente » Cod sursa (job #1288096) | Cod sursa (job #2389310) | Cod sursa (job #485827) | Cod sursa (job #999091) | Cod sursa (job #760582)
Cod sursa(job #760582)
#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,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]>=n/2 +1)
{
fout<<v[j]<<" "<<f[j];
fin.close();
fout.close();
return 0;
}
}
//if(nrmax>=n/2 +1)
//fout<<v[imax]<<" "<<nrmax;
//else
fout<<-1;
fin.close();
fout.close();
return 0;
}