Cod sursa(job #1018321)

Utilizator Lucian-GeorgeFMI Popa Lucian George Lucian-George Data 29 octombrie 2013 12:46:59
Problema Elementul majoritar Scor 0
Compilator cpp Status done
Runda Arhiva educationala Marime 0.67 kb
#include<iostream>
#include<fstream>
using namespace std;
int prez1[999999999];
	int n,v[1000001],x,elem,i,poz=0,val[1000001],ok=0;
	ifstream f("elmaj.in");
	ofstream g("elmaj.out");
int main()
{

	f>>n;
	for (i=1; i<=n; i++)
		{f>>x;
		 if (x>0) 
			if (prez1[x]==0)
			{
				poz++;
				prez1[x]=poz;
				v[poz]++;
				val[poz]=x;
			}
			else v[prez1[x]]++;
		// else
		//{
		//	x=-x;
		//	if (prez2[x]==0)
		//	{
		//		poz++;
		//		prez2[x]=poz;
		//		v[poz]++;
		//		val[poz]=-x;
		//	}
		//	else v[prez2[x]]++;
		//}
		}
	for (i=1; i<=poz; i++)
		
		{
			if (v[i]>=(n/2+1)) {ok=1; g<<val[i]<<" "<<v[i];}
		}
	if (ok==0) g<<"-1";
	return 0;
}