Cod sursa(job #2953311)

Utilizator naivejulianIulian Macovei naivejulian Data 10 decembrie 2022 22:34:44
Problema Jocul Flip Scor 20
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 2.06 kb
#include <iostream>
#include <fstream>

using namespace std;

ifstream in("flip.in");
ofstream out("flip.out");
int colectie[16][16];
int x = 0, y = 0;

int suma_rand_poz(int n) {
	int sum = 0;
	for (int j = 0; j < x; j++) {
		if (colectie[j][n]>0) {
			sum += colectie[j][n];
		}
	}
	return sum;
}
int suma_rand_neg(int n) {
	int sum = 0;
	for (int j = 0; j < x; j++) {
		if (colectie[j][n] < 0) {
			sum += colectie[j][n];
		}
	}
	return sum;
}
int suma_coloana_poz(int n) {
	int sum = 0;
	for (int i = 0; i < y; i++) {
		if (colectie[n][i] > 0) {
			sum += colectie[n][i];
		}
	}
	return sum;
}
int suma_coloana_neg(int n) {
	int sum = 0;
	for (int i = 0; i < y; i++) {
		if (colectie[n][i] < 0) {
			sum += colectie[n][i];
		}
	}
	return sum;
}

void invert_rand(int n) {
	for (int j = 0; j < x; j++) {
		colectie[j][n] = colectie[j][n]*(-1);
	}
}

void invert_coloana(int n) {
	for (int i = 0; i < y; i++) {
		colectie[n][i] *= (-1);
	}
}

int calc_tot_sum() {
	int tot_sum = 0;
	for (int i = 0; i < y; i++) {
		for (int j = 0; j < x; j++) {
			tot_sum = tot_sum + colectie[j][i];
		}
	}
	return tot_sum;
}

int main()
{
	int tot_sum_max = 0;
	int num = 0;
	in >> y;
	in >> x;
	for (int i = 0; i < y; i++) {
		for (int j = 0; j < x; j++) {
			in >> num;
			colectie[j][i] = num;
			cout << num << " ";
		}
		cout << endl;
	}
	cout << "---" << endl;
	for (int i = 0; i < y; i++) {
		for (int j = 0; j < x; j++) {
			cout << colectie[j][i] << " ";
		}
		cout << endl;
	}
	cout << suma_coloana_neg(0) << endl;
	cout << suma_coloana_poz(0) << endl;
	cout << suma_rand_neg(0) << endl;
	cout << suma_rand_poz(0) << endl;
	invert_coloana(0);
	cout << suma_coloana_neg(0) << endl;
	cout << suma_coloana_poz(0) << endl;

	for (int j = 0; j < x; j++) {
		if (abs(suma_coloana_neg(j)) > suma_coloana_poz(j)) {
			invert_coloana(j);
		}
	}

	for (int i = 0; i < x; i++) {
		if (abs(suma_rand_neg(i)) > suma_rand_poz(i)) {
			invert_rand(i);
		}
	}

	out << calc_tot_sum();

	in.close();
	out.close();
}