Pagini recente » Cod sursa (job #1382299) | Cod sursa (job #1049149) | Cod sursa (job #626732) | Cod sursa (job #637764) | Cod sursa (job #1049920)
//
// main.cpp
// elmaj
//
// Created by Catalina Brinza on 12/7/13.
// Copyright (c) 2013 Catalina Brinza. All rights reserved.
//
#include <fstream>
#include <vector>
#define nr_zone 666013
using namespace std;
ifstream f("elmaj.in");
ofstream g("elmaj.out");
struct porc
{
long long v,sum;
};
vector <porc> hashy[nr_zone];
int cautare (long long val)
{
long long zona=val%nr_zone;
for (int i=0;i<hashy[zona].size();++i)
{
if (hashy[zona][i].v==val) return i;
}
return -1;
}
int main()
{long long n,i,x,y,max=0,maxel=-1;
f>>n;
for (i=0;i<n;++i)
{
f>>x;
y=cautare(x);
if (y!=-1) {hashy[x%nr_zone][y].sum++; if (hashy[x%nr_zone][y].sum>=n/2+1 &&hashy[x%nr_zone][y].sum>max) {
max=hashy[x%nr_zone][y].sum;
maxel=x;
}}
else
{
porc q;
q.v=x;
q.sum=1;
hashy[x%nr_zone].push_back(q);
}
}
if (max==0) g<<maxel;
else g<<maxel<<' '<<max;
return 0;
}