Pagini recente » Cod sursa (job #1265482) | Cod sursa (job #1532234) | Cod sursa (job #2395780) | Cod sursa (job #2172974) | Cod sursa (job #862490)
Cod sursa(job #862490)
#include <fstream>
#include <algorithm>
#include <vector>
using namespace std;
const int MOD = 1000033;
vector<pair<int, int> > hash_table[MOD];
int main() {
int n, c(0), x;
ifstream f("elmaj.in");
ofstream g("elmaj.out");
f >> n;
for(int i = 1; i <= n; i++) {
f >> x;
int h = x % MOD;
bool found = false;
for(int j = 0; j < hash_table[h].size(); ++j) {
if(hash_table[h][j].first == x) {
hash_table[h][j].second++;
found = true;
break;
}
}
if(!found) {
hash_table[h].push_back(make_pair(x, 1));
}
}
f.close();
for(int i = 0; i < MOD; ++i) {
for(int j = 0; j < hash_table[i].size(); ++j) {
if(hash_table[i][j].second > n / 2) {
g << hash_table[i][j].first << " " << hash_table[i][j].second << endl;
g.close();
return 0;
}
}
}
g << "-1\n";
g.close();
return 0;
}