Pagini recente » Cod sursa (job #2476641) | Cod sursa (job #358825) | Cod sursa (job #2977024) | Cod sursa (job #1098967) | Cod sursa (job #906268)
Cod sursa(job #906268)
#include <fstream>
using namespace std;
int main()
{
ifstream fin("flip.in");
ofstream fout("flip.out");
int N,M,v[17][17],s=0,i,j,sneg,spoz,s1,l;
fin>>N>>M;
for(i=1;i<=N;i++)
{
sneg=0;
spoz=0;
for(j=1;j<=M;j++)
{
fin>>v[i][j];
if(v[i][j]<0)
sneg+=v[i][j];
else
spoz+=v[i][j];
}
if(spoz<-sneg)
for(l=1;l<=M;l++)
v[i][l]=-v[i][l];
}
for(j=1;j<=M;j++)
{
sneg=0;
spoz=0;
for(i=1;i<=N;i++)
{
fin>>v[i][j];
s1+=v[i][j];
if(v[i][j]<0)
sneg+=v[i][j];
else
spoz+=v[i][j];
}
if(spoz<-sneg)
for(l=1;l<=N;l++)
v[l][j]=-v[l][j];
}
s=0;
for(i=1;i<=N;i++)
for(j=1;j<=M;j++)
s+=v[i][j];
fout<<s;
return 0;
}