Pagini recente » Cod sursa (job #426233) | Cod sursa (job #3217353) | Cod sursa (job #1755674) | Cod sursa (job #236988) | Cod sursa (job #1188319)
#include <fstream>
using namespace std;
ifstream in ("flip.in");
ofstream out ("flip.out");
int const N=20;
int mat[N][N];
int main()
{
int i,j,n,m,temp1,temp2;
in>>n>>m;
for(i=1;i<=n;i++)
for(j=1;j<=m;j++)
in>>mat[i][j];
for(i=1;i<=n;i++)
{
temp1=temp2=0;
for(j=1;j<=m;j++)
{
temp1+=mat[i][j];
temp2+=mat[i][j]*(-1);
}
if(temp2>temp1)
for(j=1;j<=m;j++)
mat[i][j]=mat[i][j]*(-1);
}
for(j=1;j<=m;j++)
{
temp1=temp2=0;
for(i=1;i<=n;i++)
{
if(mat[i][j]<0) temp1+=mat[i][j];
else temp2+=mat[i][j];
}
if(temp1*(-1)>temp2)
for(i=1;i<=n;i++)
mat[i][j]=mat[i][j]*(-1);
}
temp1=0;
for(i=1;i<=n;i++)
for(j=1;j<=m;j++)
temp1+=mat[i][j];
out<<temp1;
return 0;
}