Pagini recente » Cod sursa (job #366111) | Cod sursa (job #95407) | Cod sursa (job #844270) | Cod sursa (job #591761) | Cod sursa (job #2553200)
# include <bits/stdc++.h>
using namespace std;
ifstream fin("elmaj.in");
ofstream fout ("elmaj.out");
int n, x, elmaj, f, s;
int main ()
{
fin >> n;
fin >> x;
elmaj = x;
f = 1;
for ( int i = 1; i < n; ++i)
{
fin >> x;
if ( f == 0)
elmaj = x;
if (elmaj == x)
++f;
else
--f;
}
fin.close();
fout.close();
ifstream fin ("elmaj.in");
ofstream fout ("elmaj.out");
fin >> n;
f = 0;
for ( int i = 1; i <= n; ++i)
{
fin >> x;
if(x == elmaj)
++f;
}
if(f > n/2)
fout << elmaj << " " << f;
else
fout << "-1";
return 0;
}