Cod sursa(job #1396232)

Utilizator craciuCraciun Alex craciu Data 22 martie 2015 12:31:15
Problema Jocul Flip Scor 0
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.94 kb
#include <iostream>
#include <fstream>
using namespace std;

int mat[16][16],n,m,i,j,max1,max2,s;

int main()
{
    ifstream fin("flip.in");
    fin>>n>>m;
    for(i=0;i<n;i++)
        for(j=0;j<m;j++)
            fin>>mat[i][j];
    fin.close();

    if(n>m)
    {
        for(j=0;j<m;j++)
        {
            for(i=0;i<n;i++)
            {
                max1=max1+mat[i][j];
                max2=max2+mat[i][j]*-1;
            }
            if(max2>max1)
            {
                for(i=0;i<n;i++)
                    mat[i][j]=mat[i][j]*-1;
            }
            max1=0;
            max2=0;
        }
        for(i=0;i<n;i++)
        {
            for(j=0;j<m;j++)
            {
                max1=max1+mat[i][j];
                max2=max2+mat[i][j]*-1;
            }
            if(max2>max1)
            {
                for(j=0;j<m;j++)
                    mat[i][j]=mat[i][j]*-1;
            }
            max1=0;
            max2=0;
        }
    }
    if(m>n)
    {
        for(i=0;i<n;i++)
        {
            for(j=0;j<m;j++)
            {
                max1=max1+mat[i][j];
                max2=max2+mat[i][j]*-1;
            }
            if(max2>max1)
            {
                for(j=0;j<m;j++)
                    mat[i][j]=mat[i][j]*-1;
            }
            max1=0;
            max2=0;
        }
        for(j=0;j<m;j++)
        {
            for(i=0;i<n;i++)
            {
                max1=max1+mat[i][j];
                max2=max2+mat[i][j]*-1;
            }
            if(max2>max1)
            {
                for(i=0;i<n;i++)
                    mat[i][j]=mat[i][j]*-1;
            }
            max1=0;
            max2=0;
        }
    }
    for(i=0;i<n;i++)
    {
        for(j=0;j<m;j++)
        {
            s=s+mat[i][j];
        }
    }
    //cout<<s;
    fstream fout("flip.out");
    fout<<s;
    fout.close();
    return 0;
}