Pagini recente » Cod sursa (job #349445) | Cod sursa (job #2042555) | Cod sursa (job #2232243) | Cod sursa (job #1499834) | Cod sursa (job #2189187)
#include <iostream>
#include <fstream>
#include <list>
#define M 1000003
using namespace std;
list < pair < int, int > > v[M];
int hf(int x)
{
return x%M;
}
int main()
{
int n, x, f;
list < pair < int, int > > :: iterator j;
ifstream fin("elmaj.in");
ofstream fout("elmaj.out");
fin >> n;
for (int i=1; i<=n; i++)
{
fin >> x;
f=hf(x);
for (j=v[f].begin(); j!=v[f].end(); j++)
{
if (j->first==x)
{
j->second++;
if (j->second>n/2)
{
fout << j->first << " " << j->second;
return 0;
}
break;
}
}
if (j==v[f].end())
v[f].push_back(make_pair(x, 1));
}
fout << -1;
return 0;
}