Pagini recente » Cod sursa (job #1395106) | Cod sursa (job #1511053) | Cod sursa (job #1851304) | Cod sursa (job #1836171)
#include <iostream>
#include <fstream>
#include <map>
using namespace std;
int main() {
int n;
int number;
map<int, int> apparitions;
int max = -1;
int element = -1;
ifstream input("elmaj.in");
ofstream output("elmaj.out");
input >> n;
while (n) {
input >> number;
map<int, int>::iterator index = apparitions.find(number);
if (index == apparitions.end()) {
apparitions.insert(pair<int, int>(number, 1));
n--;
continue;
}
index->second++;
if (index->second > max) {
element = number;
max = index->second;
}
n--;
}
if (element == -1)
output << element;
else
output << element << " " << max;
return 0;
}