Pagini recente » Cod sursa (job #2889143) | Cod sursa (job #961378) | Cod sursa (job #2575899) | Cod sursa (job #1260015) | Cod sursa (job #2189954)
#include <iostream>
#include<fstream>
using namespace std;
ifstream f("elmaj.in");
ofstream g("elmaj.out");
int n,cand,k,i,x,nr;
int main()
{
f>>n;
cand=-1;k=0;
for(i=1;i<=n;i++)
{
f>>x;
if(k==0)
{
cand=x;
k=1;
}
else
{
if(x==cand)
k++;
else
k--;
}
}
f.close();
ifstream f("elmaj.in");
f>>n;
for(i=1;i<=n;i++)
{
f>>x;
if(x==cand)
nr++;
}
if(nr>n/2)
g<<cand<<' '<<nr;
else g<<-1;
}