Pagini recente » Cod sursa (job #2963874) | Cod sursa (job #1496278) | Cod sursa (job #902001) | Cod sursa (job #1841628) | Cod sursa (job #3128502)
#include <iostream>
#include <fstream>
std::ifstream f("flip.in");
std::ofstream g("flip.out");
int main()
{
int n, m;
int a[20][20];
f >> n >> m;
for (int i = 0; i < n; i++)
for (int j = 0; j < m; j++)
f >> a[i][j];
int normalSum, flippedSum;
for (int i = 0; i < n; i++)
{
normalSum = 0;
flippedSum = 0;
for (int j = 0; j < m; j++)
{
normalSum += a[i][j];
flippedSum += a[i][j] * -1;
}
if (flippedSum > normalSum)
{
for (int j = 0; j < m; j++)
a[i][j] *= -1;
}
}
for (int i = 0; i < m; i++)
{
normalSum = 0;
flippedSum = 0;
for (int j = 0; j < n; j++)
{
normalSum += a[j][i];
flippedSum += a[j][i] * -1;
}
if (flippedSum > normalSum)
{
for (int j = 0; j < n; j++)
a[j][i] *= -1;
}
}
int totalSum = 0;
for (int i = 0; i < n; i++)
for (int j = 0; j < m; j++)
totalSum += a[i][j];
g << totalSum;
return 0;
}