Pagini recente » Cod sursa (job #2846518) | Cod sursa (job #3218866) | Cod sursa (job #2781456) | Cod sursa (job #2792324) | Cod sursa (job #2216537)
#include <fstream>
using namespace std;
ifstream fin ("elmaj.in");
ofstream fout ("elmaj.out");
const int Dim = 1000001;
int cnt,elmaj,x,n;
int main() {
fin >> n;
for ( int i = 1; i <= n; ++i) {
fin >> x;
if ( cnt == 0) {
elmaj = x;
cnt = 1;
}
else
{ if ( x == elmaj)
++cnt;
else
--cnt;
}
}
fin.close();
ifstream fin ("elmaj.in");
fin >> n;
cnt = 0;
for ( int i = 1; i <= n; ++i) {
fin >> x;
if ( x == elmaj)
++cnt;
}
if ( cnt > n / 2)
fout << elmaj << " " << cnt;
else
fout << -1;
}