Pagini recente » Cod sursa (job #546917) | Cod sursa (job #1355972)
#include <iostream>
#include <fstream>
using namespace std;
ifstream fin("test.in");
ofstream fout("test.out");
int main()
{
int a[100][100];
int m,n,i,j,s;
//citesc nr de ln si de col
fin >> m >> n;
//constructia matricei
for( i = 0 ; i < m ; i++ )
for( j = 0 ; j < n ; j++ )
fin >> a[i][j];
//comutare pe linii
j=0;
s=0;
while ( j < m )
{
for ( i = 0 ; i < n ; i++ )
s = s + a[j][i];
if( s < 0 )
for( i = 0 ; i < n ; i++ )
a[j][i]=a[j][i]*(-1);
j=j+1;
s=0;
}
// comutare pe coloane
s=0;
j=0;
while( j < n )
{
for ( i = 0 ; i < m ; i++ )
s = s + a[i][j];
if( s < 0 )
for ( i = 0 ; i < m ; i++ )
a[i][j]=a[i][j]*(-1);
j=j+1;
s=0;
}
// calculare suma finala
for ( i = 0 ; i < m ; i++ )
for ( j = 0 ; j < n ; j++ )
s+=a[i][j];
fout<<s;
return 0;
}