Pagini recente » Cod sursa (job #1504860) | Cod sursa (job #13689) | Cod sursa (job #1253655) | Cod sursa (job #14644) | Cod sursa (job #649738)
Cod sursa(job #649738)
#include <fstream>
#include <vector>
#include <iostream>
#define BUCKETS 200000
#define INFILE "elmaj.in"
#define OUTFILE "elmaj.out"
using namespace std;
int hash(int x)
{
return x % BUCKETS;
}
void addElement(vector<pair<int,int> > v[], int x, pair<int,int> &max)
{
int pos = hash(x);
for(vector<pair<int,int> >::iterator it = v[pos].begin(); it != v[pos].end(); ++it) {
if (it->first == x) {
++it->second;
if (it->second > max.second)
max = *it;
return;
}
}
pair<int,int> p(x,1);
if (max.second < 1)
max = p;
v[pos].push_back(p);
}
int main()
{
pair<int,int> max(0,0);
int n;
vector<pair<int,int> > tabela[BUCKETS];
ifstream fin(INFILE);
ofstream fout(OUTFILE);
fin >> n;
for(int i = 0; i<n; ++i){
int k;
fin >> k;
addElement(tabela, k, max);
}
if (max.second > n/2)
fout << max.first << " " << max.second << endl;
else
fout << "-1\n";
fin.close();
fout.close();
return 0;
}