Cod sursa(job #1707445)
Utilizator | Data | 25 mai 2016 08:24:49 | |
---|---|---|---|
Problema | Elementul majoritar | Scor | 50 |
Compilator | cpp | Status | done |
Runda | Arhiva educationala | Marime | 0.34 kb |
#include <bits/stdc++.h>
using namespace std;
ifstream fin("elmaj.in");ofstream fout("elmaj.out");
unordered_map<int,int>aparitii;int x,n;
int main()
{
fin>>n;bool ok=false;
for(int copn=n;copn;--copn){fin>>x;aparitii[x]++;if(aparitii[x]>=(n/2+1)){fout<<x<<' '<<aparitii[x];ok=true;break;}}
if(!ok) fout<<-1;
return 0;
}