Pagini recente » Cod sursa (job #1263207) | Cod sursa (job #2251851) | Cod sursa (job #1075005) | Cod sursa (job #2246971) | Cod sursa (job #743058)
Cod sursa(job #743058)
#include <fstream>
#include <set>
#include <vector>
#define mp make_pair
using namespace std;
class ComparePairs {
public:
bool operator() (const pair<int, int>& a, const pair<int, int>& b) const {
return a.first < b.first;
}
};
int main() {
bool ok = false;
int size;
int i;
int val;
int old_count;
ifstream in_file("elmaj.in");
ofstream out_file("elmaj.out");
set<pair<int, int>, ComparePairs> aset;
set<pair<int, int>, ComparePairs>::iterator it;
in_file >> size;
for (i = 0; i < size; ++i) {
in_file >> val;
if ((it = aset.find(mp(val, 0))) != aset.end()) {
old_count = (*it).second;
aset.erase(it);
aset.insert(mp(val, old_count + 1));
} else {
aset.insert(mp(val, 1));
}
}
size >>= 1;
for (it = aset.begin(); it != aset.end(); ++it) {
if ((*it).second > size) {
ok = true;
break;
}
}
if (ok == true) {
out_file << (*it).first << " " << (*it).second;
} else {
out_file << "-1";
}
in_file.close();
out_file.close();
return 0;
}