Cod sursa(job #162474)
#include <iostream>
#include <fstream>
using namespace std;
long m,n;
int GetSumRows(int **matrix, int row , int com)
{
int s = 0;
for(int col=0;col<n;col++)
{
s += matrix[row][col] * com ;
}
return s;
}
void SetRows(int **matrix, int row , int com)
{
for(int col=0;col<n;col++)
{
matrix[row][col] = matrix[row][col] * com;
}
}
int GetSumCols(int **matrix, int col , int com)
{
int s = 0;
for(int row=0;row<m;row++)
{
s += com * matrix[row][col];
}
return s;
}
void SetCols(int **matrix, int col , int com)
{
for(int row=0;row<m;row++)
{
matrix[row][col] = matrix[row][col] * com;
}
}
void ShowMatrix(int **matrix)
{
for(int i=0;i<m;i++)
{
for(int j=0;j<n;j++)
cout<<matrix[i][j]<<" ";
cout<<endl;
}
}
int GetSumMatrix(int **matrix)
{
int s=0;
for(int i=0;i<m;i++)
{
for(int j=0;j<n;j++)
s += matrix[i][j];
}
return s;
}
void ReadFromFile(ifstream &fin, int **matrix)
{
for(int i=0;i<m;i++)
{
matrix[i] = new int[n];
for(int j=0;j<n;j++)
{
fin>>matrix[i][j];
}
}
}
void WriteToFile(ofstream &fout, int **matrix)
{
fout<<GetSumMatrix(matrix);
}
int main()
{
ifstream fin("flip.in");
ofstream fout("flip.out",ios::out);
fin>>m>>n;
int **matrix = (int **)new int();
ReadFromFile(fin,matrix);
//ShowMatrix(matrix);
for(int i=0;i<m;i++)
{
if(GetSumRows(matrix,i,-1)>GetSumRows(matrix,i,1))
SetRows(matrix,i,-1);
}
for(int j=0;j<n;j++)
{
if(GetSumCols(matrix,j,-1)>GetSumCols(matrix,j,1))
SetCols(matrix,j,-1);
}
//ShowMatrix(matrix);
WriteToFile(fout,matrix);
fin.close();
fout.close();
return 0;
}