Cod sursa(job #2016029)

Utilizator bebopZaharia Mihai bebop Data 28 august 2017 14:35:45
Problema Jocul Flip Scor 40
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.15 kb
#include<iostream>
#include<fstream>

#define intrare "flip.in"
#define iesire "flip.out"

using namespace std;

int main() {
	ifstream f(intrare);
	ofstream g(iesire);

	int n, m, sum,sum2,sum1,ok1,ok2;
	f >> n >> m;
	int A[17][17];
	int B[2][17];
	sum = 0;
	for (int i = 0; i < n; i++)
		for (int j = 0; j < m; j++) {
			f >> A[i][j];
			sum += A[i][j];
		}
	sum = 0;

	for (int i = 0; i < n; i++)
		for (int j = 0; j < m; j++) {
			sum1 = 0;
			sum2 = 0;
			ok1 = 0;
			ok2 = 0;
			for (int k = 0; k < m; k++)
				sum2 += A[i][k];
			for (int x = 0; x < n; x++)
				sum1 += A[x][j];
			if (sum1 < 0)
				ok1 = 1;
			if (sum2 < 0)
				ok2 = 1;
			if (ok1==1&&ok2==1)
				if (abs(sum1) > abs(sum2)) {
					for (int w = 0; w < n; w++)
						A[w][j] *= (-1);
				}
				else
					for (int w = 0; w < m; w++)
						A[i][w] *= (-1);
			else {
				if (ok1 == 1) {
					for (int w = 0; w < n; w++)
						A[w][j] *= (-1);
				}
				else if(ok2==1)
					for (int w = 0; w < m; w++)
						A[i][w] *= (-1);
			}

		}
	for (int i = 0; i < n; i++)
		for (int j = 0; j < m; j++)
			sum += A[i][j];

	g << sum;
	
	return 0;
}