Cod sursa(job #2374858)

Utilizator HelloWorldBogdan Rizescu HelloWorld Data 7 martie 2019 20:56:19
Problema Elementul majoritar Scor 90
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.43 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]++;
   }
   for (auto it:m)
   {
       if (it.second>n/2)
       {
           elmaj=1;
           out<<it.first<<" "<<it.second<<"\n";
           break;
       }
   }
   if (!elmaj) out<<"-1\n";
}