Pagini recente » Cod sursa (job #1845912) | Cod sursa (job #590531) | Cod sursa (job #1343653) | Cod sursa (job #882825) | Cod sursa (job #1836170)
#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));
continue;
}
index->second++;
if (index->second > max) {
element = number;
max = index->second;
}
n--;
}
if (element == -1)
output << element;
else
output << element << " " << max;
return 0;
}