Pagini recente » Rating Calancea Roxana (roxana_maria) | Cod sursa (job #2903649) | Cod sursa (job #2359767) | Cod sursa (job #436251) | Cod sursa (job #1171670)
#include <fstream>
#include <map>
using namespace std;
int N;
map<int, int> mappings;
map<int,int>::iterator it;
ifstream fin("elmaj.in");
ofstream fout("elmaj.out");
int main(){
fin >> N;
int x, count = -1, who = -1;
for(int i = 0; i < N; i++){
fin >> x;
it = mappings.find(x);
if(it == mappings.end())
mappings[x] = 1;
else
mappings[x] += 1;
}
for (map<int,int>::iterator it=mappings.begin(); it!=mappings.end(); ++it){
if(it->second > count){
count = it->second;
who = it->first;
}
}
if(count >= N/2 + 1)
fout << who << " " << count << "\n";
else
fout << "-1\n";
return 0;
}