Cod sursa(job #1026113)

Utilizator AndreeaPanaitAndreea Elena Panait AndreeaPanait Data 11 noiembrie 2013 09:17:00
Problema Elementul majoritar Scor 0
Compilator cpp Status done
Runda Arhiva educationala Marime 0.66 kb
// Elem_Maj.cpp : Defines the entry point for the console application.
//


#include<fstream>

using namespace std;



int n, x, a[1000010], max=0, nr;

int main()
{
	//ifstream f("F:/andreea/Scoala/FMI 2013/probleme fac I/infoarena/Elem_Maj/Debug/elmaj.in");
	//ofstream g("F:/andreea/Scoala/FMI 2013/probleme fac I/infoarena/Elem_Maj/Debug/elmaj.out");

	ifstream f("elmaj.in");
	ofstream g("elmaj.out");


	f >> n;
	for (int i = 1; i <= n; i++)
	{
		f >> x; 
		a[x]++;

		if (a[x]>max)
		{
			max = a[x]; 
			nr = x;
		}
	}
	
	if (max >= n / 2 + 1)
		g << nr << " " << max;
	else
		g << -1;

	f.close(); 
	g.close();

return 0;
}