Cod sursa(job #721414)
| Utilizator | Data | 23 martie 2012 18:07:43 | |
|---|---|---|---|
| Problema | Elementul majoritar | Scor | 40 |
| Compilator | cpp | Status | done |
| Runda | Arhiva educationala | Marime | 0.49 kb |
#include<fstream>
#include<set>
using namespace std;
typedef multiset<int> mset;
int main()
{
ifstream fin("elmaj.in");
ofstream fout("elmaj.out");
int nA; fin>>nA;
mset A;
for (int i=1;i<=nA;i++)
{
int tmp; fin>>tmp;
A.insert(tmp);
}
int maj=-1;
for (mset::iterator it=A.begin();it!=A.end();++it)
if (A.count(*it)>A.size()/2) maj=*it;
fout<<maj<<' ';
if (maj!=-1)
fout<<A.count(maj);
return 0;
}
