Pagini recente » Cod sursa (job #662916) | Cod sursa (job #1365703) | Cod sursa (job #1510858) | Cod sursa (job #957875) | Cod sursa (job #649724)
Cod sursa(job #649724)
#include <fstream>
#include <vector>
#include <iostream>
#define BUCKETS 66613
#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)
{
vector<pair<int,int> > list = v[hash(x)];
for(vector<pair<int,int> >::iterator it = list.begin(); it != list.end(); ++it) {
if (it->first == x) {
++it->second;
if (it->second > max.second)
max = *it;
break;
}
cout << it->first << endl;
}
pair<int,int> p(x,1);
if (max.second < 1)
max = p;
list.push_back(p);
v[hash(x)] = list;
}
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;
}