Cod sursa(job #2374854)

Utilizator HelloWorldBogdan Rizescu HelloWorld Data 7 martie 2019 20:55:00
Problema Elementul majoritar Scor 90
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.48 kb
#include <fstream>
#include <map>
using namespace std;
ifstream in("elmaj.in");
ofstream out("elmaj.out");
int n,elmaj,i,x;
map <int,int> m;
int main()
{
   in>>n;
   for (i=1;i<=n;++i)
   {
       in>>x;
       m[x]++;
   }
   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";
}