Cod sursa(job #2375324)
| Utilizator | Data | 8 martie 2019 00:56:27 | |
|---|---|---|---|
| Problema | Elementul majoritar | Scor | 100 |
| Compilator | cpp-64 | Status | done |
| Runda | Arhiva educationala | Marime | 0.48 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;
ios::sync_with_stdio(0);
for (i=1;i<=n;++i)
{
in>>x;
m[x]++;
}
for (auto it:m)
{
if (it.second>n/2)
{
elmaj=1;
out<<it.first<<" "<<it.second<<"\n";
break;
}
}
if (!elmaj) out<<"-1\n";
}
