Pagini recente » Cod sursa (job #3148850) | Cod sursa (job #861551) | Cod sursa (job #1653982) | Cod sursa (job #2192991) | Cod sursa (job #216847)
Cod sursa(job #216847)
#include <fstream>
using namespace std;
ifstream fin("flip.in");
ofstream fout("flip.out");
int m,n;
int mat[16][16];
int Sp,Sn,Stot;
int main()
{
fin>>m>>n;
for (int i=0;i<m;i++)
for (int j=0;j<n;j++)
fin>>mat[i][j];
//pe randuri
for (int i=0;i<m;i++)
{
Sp=Sn=0;
for (int j=0;j<n;j++)
if (mat[i][j]>0)
Sp+=mat[i][j];
else
Sn-=mat[i][j];
if (Sn>Sp)
for (int j=0;j<n;j++) mat[i][j]*=-1;
}
//pe coloane
for (int i=0;i<n;i++)
{
Sp=Sn=0;
for (int j=0;j<m;j++)
if (mat[j][i]>0)
Sp+=mat[j][i];
else
Sn-=mat[j][i];
if (Sn>Sp)
for (int j=0;j<m;j++) mat[j][i]*=-1;
}
//suma totala
Stot=0;
for (int i=0;i<m;i++)
for (int j=0;j<n;j++)
Stot+=mat[i][j];
fout<<Stot<<'\n';
fout.close();
return 0;
}