Pagini recente » Cod sursa (job #395249) | Cod sursa (job #2028306) | Cod sursa (job #1415946) | Cod sursa (job #541106) | Cod sursa (job #2094159)
#include <iostream>
#include <algorithm>
#include <map>
#include <fstream>
using namespace std;
int main(void)
{
ifstream inp("elmaj.in");
ofstream out("elmaj.out");
if(inp.is_open() && out.is_open())
{
map<int, int> hashtable;
int n;
inp >> n;
bool found = false;
for(int i = 0; i < n; i++)
{
int t;
inp >> t;
hashtable[t]++;
if(hashtable[t] >= (n/2 + 1))
{
found = true;
out << t << " " << hashtable[t];
break;
}
}
if(!found)
{
out << "-1";
}
inp.close();
out.close();
}
else
{
cout << "error\n";
}
return 0;
}