Pagini recente » Cod sursa (job #556793) | Cod sursa (job #2312954) | Cod sursa (job #2231735) | Cod sursa (job #1959662) | Cod sursa (job #2461281)
# include <fstream>
# include <map>
using namespace std;
ifstream fin("elmaj.in");
ofstream fout("elmaj.out");
int main()
{
int n, x, ok = 0;
int max = 0, maxv = 0, find = 0;
map<int, int>dictionar;
fin >> n;
for (int i = 0; i < n; i++)
{
fin >> x;
if (dictionar.find(x)->second)
{
dictionar.find(x)->second++;
if (dictionar.find(x)->second > n/2)
{
find = 1;
max = x;
maxv = dictionar.find(x)->second;
}
}
else
dictionar.insert(pair<int, int >(x, 1));
}
if (find)
fout << max << " " << maxv;
else
fout << "-1";
return 0;
}