Pagini recente » Cod sursa (job #1592548) | Cod sursa (job #2004794) | Cod sursa (job #110150) | Cod sursa (job #46232) | Cod sursa (job #2148738)
#include <bits/stdc++.h>
using namespace std;
int main()
{
ifstream fin ("elmaj.in");
int x , maj , s , n;
fin >> n;
fin >> x;
s = 1;
maj = x;
for(int i = 2 ; i <= n ; i++)
{
fin >> x;
s -= ! (maj == x);
if(s <= 0)
{
s = 0;
maj = x;
}
}
s = 0;
fin.close();
fin.open("elmaj.in");
fin >> n >> x;
s += (maj == x);
for(int i = 2 ; i <= n ; i++)
{
fin >> x;
s += (maj == x);
}
ofstream fout("elmaj.out");
if(s > n / 2)
fout << maj << " " << s << "\n";
else fout << "-1\n";
fin.close();
fout.close();
return 0;
}