Pagini recente » Cod sursa (job #1118458) | Cod sursa (job #1948409) | Cod sursa (job #209358) | Cod sursa (job #2810097) | Cod sursa (job #1064591)
#include <fstream>
#include <vector>
using namespace std;
ifstream fin("elmaj.in");
ofstream fout("elmaj.out");
struct per
{
int val, nr_ap;
};
vector<per> hashh[666013];
int max_ap, elmaj;
int N;
int main()
{
int i, x, j;
fin >> N;
for( i = 1; i <= N; i++)
{
fin >> x;
int ok = 0, key = x % 666013;
for(j = 0; j < hashh[key].size() && !ok; j++)
if(hashh[key][j].val == x)
{
ok = 1;
hashh[key][j].nr_ap ++;
if( hashh[key][j].nr_ap > max_ap)
{
max_ap = hashh[key][j].nr_ap;
elmaj = x;
}
}
if(! ok)
{
per aux;
aux.val = x;
aux.nr_ap = 1;
if(max_ap == 0)
{
max_ap = 1;
elmaj = x;
}
hashh[key].push_back(aux);
}
}
if(max_ap >= N / 2 + 1)fout<<elmaj <<" "<<max_ap;
else fout<<-1;
return 0;
}