Pagini recente » Cod sursa (job #807379) | Cod sursa (job #2862056) | Cod sursa (job #2862061) | Cod sursa (job #2403254) | Cod sursa (job #1258586)
#include <iostream>
#include <fstream>
using std::ifstream;
using std::ofstream;
int main(){
int n, m, neg, poz, max = 0;
int **matrice;
ifstream input("flip.in");
ofstream output("flip.out");
input >> n >> m;
matrice = new int*[n];
for (int i = 0; i < n; i++)
matrice[i] = new int[m];
for (int j = 0; j < n; j++){
neg = 0;
poz = 0;
for (int i = 0; i < m; i++){
input >> matrice[i][j];
if (matrice[i][j]>0)
poz += matrice[i][j];
else
neg += matrice[i][j];
}
if (neg*(-1) > poz)
for (int i = 0; i < m; i++)
matrice[i][j] *= -1;
}
for (int i = 0; i < m; i++){
neg = 0;
poz = 0;
for (int j = 0; j < n; j++){
if (matrice[i][j]>0)
poz += matrice[i][j];
else
neg += matrice[i][j];
}
if (neg*(-1) > poz)
for (int j = 0; j < n; j++)
matrice[i][j] *= -1;
}
for (int j = 0; j < n; j++)
for (int i = 0; i < m; i++)
max += matrice[i][j];
output << max;
return 0;
}