Pagini recente » Cod sursa (job #1863916) | Cod sursa (job #2748163) | Cod sursa (job #2981578) | Cod sursa (job #48082) | Cod sursa (job #2553203)
# 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");
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;
}