Pagini recente » Cod sursa (job #2451202) | Cod sursa (job #691721) | Cod sursa (job #3226428) | Cod sursa (job #1038374) | Cod sursa (job #2374908)
#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]++;
if (m[x]>n/2)
{
elmaj=1;
out<<x<<" "<<m[x]<<"\n";
break;
}
}
if (!elmaj)
{
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";
}
}