Pagini recente » Cod sursa (job #3329101) | Cod sursa (job #765831) | Cod sursa (job #873068) | Cod sursa (job #693886) | Cod sursa (job #1049963)
//
// 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");
vector <pair <int,int>> hashy[nr_zone];
int cautare (long long val, long long zona)
{
for (int i=0;i<hashy[zona].size();++i)
{
if (hashy[zona][i].first==val) return i;
}
return -1;
}
int main()
{long long n,i,x,y,max=0,maxel=-1;
f>>n;
bool ok=false;
for (i=0;i<n;++i)
{
f>>x;
if (!ok)
{
long long k=x%nr_zone;
y=cautare(x,k);
if (y!=-1) {
++hashy[k][y].second;
if (hashy[k][y].second==(n>>1)+1)
{maxel=x;
max=hashy[k][y].second; ok=true;
}}
else
hashy[k].push_back(make_pair(x,1));
}
else if (x==maxel) ++max;
}
if (max==0) g<<maxel;
else g<<maxel<<' '<<max;
return 0;
}