Pagini recente » Cod sursa (job #2201954) | Cod sursa (job #1337367) | Cod sursa (job #979433) | Cod sursa (job #2201980) | Cod sursa (job #1396232)
#include <iostream>
#include <fstream>
using namespace std;
int mat[16][16],n,m,i,j,max1,max2,s;
int main()
{
ifstream fin("flip.in");
fin>>n>>m;
for(i=0;i<n;i++)
for(j=0;j<m;j++)
fin>>mat[i][j];
fin.close();
if(n>m)
{
for(j=0;j<m;j++)
{
for(i=0;i<n;i++)
{
max1=max1+mat[i][j];
max2=max2+mat[i][j]*-1;
}
if(max2>max1)
{
for(i=0;i<n;i++)
mat[i][j]=mat[i][j]*-1;
}
max1=0;
max2=0;
}
for(i=0;i<n;i++)
{
for(j=0;j<m;j++)
{
max1=max1+mat[i][j];
max2=max2+mat[i][j]*-1;
}
if(max2>max1)
{
for(j=0;j<m;j++)
mat[i][j]=mat[i][j]*-1;
}
max1=0;
max2=0;
}
}
if(m>n)
{
for(i=0;i<n;i++)
{
for(j=0;j<m;j++)
{
max1=max1+mat[i][j];
max2=max2+mat[i][j]*-1;
}
if(max2>max1)
{
for(j=0;j<m;j++)
mat[i][j]=mat[i][j]*-1;
}
max1=0;
max2=0;
}
for(j=0;j<m;j++)
{
for(i=0;i<n;i++)
{
max1=max1+mat[i][j];
max2=max2+mat[i][j]*-1;
}
if(max2>max1)
{
for(i=0;i<n;i++)
mat[i][j]=mat[i][j]*-1;
}
max1=0;
max2=0;
}
}
for(i=0;i<n;i++)
{
for(j=0;j<m;j++)
{
s=s+mat[i][j];
}
}
//cout<<s;
fstream fout("flip.out");
fout<<s;
fout.close();
return 0;
}