Pagini recente » Cod sursa (job #1252692) | Cod sursa (job #1124851) | Cod sursa (job #116085) | Cod sursa (job #2351277) | Cod sursa (job #2148814)
#include <iostream>
#include <map>
#include <unordered_map>
#include <fstream>
using namespace std;
ifstream in("elmaj.in");
ofstream out("elmaj.out");
unordered_map <int, int> schema;
int main()
{
int n;
in>>n;
for(register int i=1;i<=n;i++)
{
int x;
in>>x;
schema[x]++;
}
int max_value=0;
int max_count=0;
register unordered_map <int, int> ::iterator itr;
for(itr = schema.begin(); itr!=schema.end();itr++)
{
int itr_count=itr->second;
if(itr_count>max_count)
{
int itr_value=itr->first;
max_value=itr_value;
max_count=itr_count;
}
}
if(max_count>n/2)
out<<max_value<<" "<<max_count;
else
out<<-1;
}