Pagini recente » tema | Cod sursa (job #2506977) | Cod sursa (job #2377736) | Cod sursa (job #342049) | Cod sursa (job #2171411)
#include <fstream>
#include <algorithm>
using namespace std;
ifstream cin("elmaj.in");
ofstream cout("elmaj.out");
void sortMajority(int n, int a[]) {
sort(a, a+n);
int i = 0, ok=0;
while (i < n) {
int j = i;
while (j < n && a[j + 1] == a[i])
j++;
if ((j-i+1) > n/2)
cout << a[i] << ' ' << j, ok=1;
i = j + 1;
}
if(ok==0)
cout << -1;
}
int main()
{
int n, a[100005], i;
cin >> n;
for(i=0; i<n; i++)
cin >> a[i];
sortMajority(n, a);
}