Cod sursa(job #1404045)

Utilizator razvang10Razvan Girboveanu razvang10 Data 27 martie 2015 19:02:23
Problema Jocul Flip Scor 20
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.35 kb
#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();
    schimbrand();
    schimbcoloana();
    for(int i=0;i<n;i++)
    {
          for(int j=0;j<m;j++)
        {
            maxim=maxim+tabla[i][j];
        }
    }
    ofs<<maxim;
}