Cod sursa(job #2375326)
| Utilizator | Data | 8 martie 2019 00:58:44 | |
|---|---|---|---|
| Problema | Elementul majoritar | Scor | 100 |
| Compilator | cpp-64 | Status | done |
| Runda | Arhiva educationala | Marime | 0.51 kb |
#include <fstream>
#include <unordered_map>
using namespace std;
ifstream in("elmaj.in");
ofstream out("elmaj.out");
int n,elmaj,i,x;
unordered_map <int,int> m;
int main()
{
in>>n;
for (i=1;i<=n;++i)
{
in>>x;
m[x]++;
}
unordered_map <int,int>::iterator it;
for (it=m.begin();it!=m.end();++it)
{
if (it->second>n/2)
{
elmaj=1;
out<<it->first<<" "<<it->second<<"\n";
break;
}
}
if (!elmaj) out<<"-1\n";
}
