Pagini recente » Cod sursa (job #3351451) | Cod sursa (job #1929832) | Cod sursa (job #2948553) | Cod sursa (job #3273886) | Cod sursa (job #1836160)
#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;
if( apparitions.find(number) == apparitions.end() )
{
apparitions.insert(pair<int,int>(number,1));
}
else
{
map<int,int>::iterator index = apparitions.find(number);
index->second++;
if(index->second > max)
{
element = number;
max = index->second;
}
}
n--;
}
if(element == -1 )
output << element;
else
output << element << " " << max;
return 0;
}