Pagini recente » Istoria paginii runda/franceza/clasament | Cod sursa (job #786203) | tema | Cod sursa (job #2763204) | Cod sursa (job #1404013)
#include <iostream>
#include <fstream>
using namespace std;
int n,m;
int tabla[20][20];
int invers,normal,maxim=0;
void schimbrand()
{
for(int i=0;i<n;i++)
{
invers=0;
normal=0;
for(int j=0;j<m;j++)
{
normal=normal+tabla[i][j];
invers=invers+tabla[i][j]*(-1);
}
if (invers>normal)
{
for(int j=0;j<m;j++)
{
tabla[i][j]=tabla[i][j]*(-1);
}
}
}
}
void schimbcoloana()
{
for(int j=0;j<m;j++)
{
invers=0;
normal=0;
for(int i=0;i<n;i++)
{
normal=normal+tabla[i][j];
invers=invers+tabla[i][j]*(-1);
}
if (invers>normal)
{
for(int i=0;i<n;i++)
{
tabla[i][j]=tabla[i][j]*(-1);
}
}
}
}
int main()
{
ifstream ifs( "flip.in" );
ofstream ofs( "flip.out" );
ifs>>n>>m;
for(int i=0;i<n;i++)
{
for(int j=0;j<m;j++)
{
ifs>>tabla[i][j];
}
}
schimbrand();
schimbcoloana();
for(int i=0;i<n;i++)
{
for(int j=0;j<m;j++)
{
maxim=maxim+tabla[i][j];
}
}
ofs<<maxim;
}