Cod sursa(job #2191819)

Utilizator Florin77Nacu Florin Florin77 Data 3 aprilie 2018 19:51:51
Problema Jocul Flip Scor 20
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.89 kb
#include<iostream>
#include<fstream>
using namespace std;

int N, M, a[100][100];

void comutare_linie(int l)
{
	for (int z = 1; z <= M; z++)
		a[l][z] = -a[l][z];
}

void comutare_coloana(int c)
{
	for (int z = 1; z <= N; z++)
		a[z][c] = -a[z][c];
}

void suma_matrice(int& s)
{
	s = 0;
	for (int p = 1; p <= N; p++)
		for (int q = 1; q <= M; q++)
			s += a[p][q];
}

int main()
{
	ifstream f("flip.in");
	ofstream g("flip.out");
	int i, j;
	f >> N >> M;
	for (i = 1; i <= N; i++)
		for (j = 1; j <= M; j++)
			f >> a[i][j];
	f.close();
	int max, s;
	suma_matrice(max);
	for (i = 1; i <= N; i++)
	{
		comutare_linie(i);
		suma_matrice(s);
		if (s > max)
			max = s;
		else
			comutare_linie(i);
	}
	for (j = 1; j <= M; j++)
	{
		comutare_coloana(j);
		suma_matrice(s);
		if (s > max)
			max = s; 
		else
			comutare_coloana(j);
	}
	g << max;
	g.close();
}