Cod sursa(job #970259)

Utilizator soroceanalexsoroceanalex soroceanalex Data 6 iulie 2013 13:56:28
Problema Jocul Flip Scor 0
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.14 kb
#include<fstream>
using namespace std;

long **elements;
long lineNr;
long columnNr;

void checkLines()
{
	for (long i = 0; i < lineNr; i++)
	{	
		long sum  = 0;
		for (long j = 0; j < columnNr; j++)
			sum += elements[i][j];
		if  (sum < 0) 
			for (long l = 0; l < columnNr; l++)
				elements[i][l] *= -1;
	}		
}

void checkColumns()
{
	for (long i = 0; i < columnNr; i++)
	{	
		long sum  = 0;
		for (long j = 0; j < lineNr; j++)
			sum += elements[j][i];
		if  (sum < 0) 
			for (long l = 0; l < lineNr; l++)
				elements[l][i] *= -1;
	}	

}

long countSum()
{
	checkLines();
	checkColumns();
	long sum = 0;
	for (long i = 0; i < lineNr; i++)
	{	
		for (long j = 0; j < columnNr; j++)
			sum += elements[i][j];
	}	
	return sum;
}
long main()
{
		ifstream fin("flip.in");
		ofstream fout("flip.out");

		fin>>lineNr>>columnNr;
		elements = new long* [lineNr];
		for (long i = 0; i < lineNr; i++)
			elements[i]	= new long[columnNr];
		for (long i = 0; i <lineNr; i++)
			for (long j = 0; j < columnNr; j++)
				fin>>elements[i][j];
		checkLines();
		checkColumns();
		fout<<countSum();

}