Pagini recente » Cod sursa (job #1520276) | Cod sursa (job #247957) | Cod sursa (job #1937262) | Cod sursa (job #1694051) | Cod sursa (job #645745)
Cod sursa(job #645745)
#include<fstream>
#include<vector>
#define hk 666013
using namespace std;
ifstream f("elmaj.in");
ofstream g("elmaj.out");
int elmaj,nap,n;
vector < pair <int,int> > hash_map[666013];
int main(){
f>>n;
int x,verif;
for(int i=1;i<=n;i++){
f>>x;
verif=0;
if(!hash_map[x%hk].empty()){
for(unsigned int j=0;j<=hash_map[x%hk].size();j++)
if(hash_map[x%hk][j].first==x){
hash_map[x%hk][j].second++;
verif=1;
if(nap<hash_map[x%hk][j].second){
nap=hash_map[x%hk][j].second;
elmaj=x;
}
}
}
if(verif==0)
hash_map[x%hk].push_back(make_pair(x,1));
}
if(nap>=n/2+1){
g<<elmaj<<" "<<nap;
}
else
g<<"-1";
return 0;
}