Cod sursa(job #1009972)
Utilizator | Data | 14 octombrie 2013 01:19:22 | |
---|---|---|---|
Problema | Elementul majoritar | Scor | 0 |
Compilator | cpp | Status | done |
Runda | Arhiva educationala | Marime | 0.43 kb |
#include<fstream>
#include<iostream>
#include<map>
using namespace std;
int N,x,ma;
map<int,int> M;
int main()
{
ifstream fin("elmaj.in");
ofstream fout("elmaj.out");
fin>>N;
for(int i=1;i<=N;++i)
{
fin>>x;
M[x]=M[x]+1;
if(M[x]>N/2)
ma = x;
}
if(ma==0)
cout<<0<<endl;
else
cout<<ma<<" "<<M[ma]<<endl;
return 0;
}