Pagini recente » Cod sursa (job #984559) | Cod sursa (job #2564120) | Cod sursa (job #1382766) | Cod sursa (job #2159218) | Cod sursa (job #1786966)
#include <iostream>
#include <fstream>
#include <map>
using namespace std;
ifstream fin("elmaj.in");
ofstream fout("elmaj.out");
map<int, int> m;
int main()
{
int i, x, ap, n, maj, ok=0;
fin>>n;
maj=n/2+1;
for(i=1;i<=n;i++){
fin>>x;
if(m.find(x)->first == 0){
m.insert(pair<int, int>(x, 1));
}else{
ap = m.find(x)->second;
m.erase(x);
m.insert(pair<int, int>(x, ap+1));
}
}
/*
for(i=0;i<m.size();i++){
if(m[i]>=maj){
fout<<i<<" "<<m[i];
ok=1;
break;
}
}
if(ok==0) fout<<"-1";
*/
map<int, int>::iterator pos;
for(pos=m.begin();pos!=m.end();++pos){
if(pos->second>=maj){
ok=1;
cout<<pos->first<<" "<<pos->second;
break;
}
}
if(ok==0) cout<<-1;
return 0;
}