Pagini recente » Cod sursa (job #2427073) | Cod sursa (job #1944311) | Cod sursa (job #311758) | Cod sursa (job #250419) | Cod sursa (job #3183949)
#include <iostream>
#include <fstream>
using namespace std;
ifstream fin ("elmaj.in");
ofstream fout ("elmaj.out");
int t[1000005];
int main()
{
int i, n, bum=1,j, nrmaj,c=0;
fin >> n;
for (i=1;i<=n;i++)
{
fin >> t[i];
}
nrmaj=t[1];
for (i=2;i<=n;i++)
{
if (t[i]==nrmaj)
{
bum++;
}
else
{
bum--;
}
if (bum<0)
{
nrmaj=t[i];
bum=1;
}
}
for (i=1;i<=n;i++)
{
if (t[i]==nrmaj)
{
c++;
}
}
fout << nrmaj << " " << c;
return 0;
}