Pagini recente » Cod sursa (job #2908388) | Cod sursa (job #468391) | Cod sursa (job #575163) | arhiva-educationala | Cod sursa (job #65410)
Cod sursa(job #65410)
#include<stdio.h>
int main()
{int N,M,i,j;
long a[17][17],s,S=0;
FILE*f,*g;
f=fopen("flip.in","r");
g=fopen("flip.out","w");
fscanf(f,"%d %d",&N,&M);
for(i=1;i<=N;i++)
for(j=1;j<=M;j++)
fscanf(f,"%ld",&a[i][j]);
for(j=1;j<=M;j++)
{s=0;
for(i=1;i<=N;i++)
s+=a[i][j];
if(s<0) for(i=1;i<=N;i++)
a[i][j]=-a[i][j];}
for(i=1;i<=N;i++)
{s=0;
for(j=1;j<=M;j++)
s+=a[i][j];
if(s<0) for(j=1;j<=M;j++)
a[i][j]=-a[i][j];}
for(i=1;i<=N;i++)
for(j=1;j<=M;j++)
S+=a[i][j];
fprintf(g,"%ld",S);
fclose(f);
fclose(g);
return 0;
}