Cod sursa(job #2198849)

Utilizator @@@-.-@@@Petri Dragos @@@-.-@@@ Data 25 aprilie 2018 17:58:16
Problema Jocul Flip Scor 0
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.57 kb
#include <iostream>
#include <fstream>
using namespace std;

int main()
{
    ifstream f("flip.in");
    ofstream g("flip.out");
    int m, n, sumcurent=0, sumpotential=0, i, j, sum=0;
    f>>m>>n;
    int mat[m][n];
    for (i=0; i<m; ++i)
        for (j=0; j<n; ++j)
        f>>mat[i][j];
    for (j=0;j<n;++j){
        for (i=0;i<m;++i) sumcurent+=mat[i][j];
        for (i=0;i<m;++i) mat[i][j]*=-1;
        for (i=0;i<m;++i) sumpotential+=mat[i][j];
        if (sumcurent>sumpotential) for (i=0;i<m;++i) mat[i][j]*=-1;
        sumcurent=0;
        sumpotential=0;
    }
    for (i=0;i<m;++i) {
        for (j=0; j<n;++j) sumcurent+=mat[i][j];
        for (j=0; j<n;++j) mat[i][j]*=-1;
        for (j=0; j<n;++j) sumpotential+=mat[i][j];
        if (sumcurent>sumpotential) for (j=0;j<n;++j) mat[i][j]*=-1;
        sumcurent=0;
        sumpotential=0;
    }
    for (i=0;i<m;++i) {
        for (j=0; j<n;++j) sumcurent+=mat[i][j];
        for (j=0; j<n;++j) mat[i][j]*=-1;
        for (j=0; j<n;++j) sumpotential+=mat[i][j];
        if (sumcurent>sumpotential) for (j=0;j<n;++j) mat[i][j]*=-1;
        sumcurent=0;
        sumpotential=0;
    }
    for (j=0;j<n;++j){
        for (i=0;i<m;++i) sumcurent+=mat[i][j];
        for (i=0;i<m;++i) mat[i][j]*=-1;
        for (i=0;i<m;++i) sumpotential+=mat[i][j];
        if (sumcurent>sumpotential) for (i=0;i<m;++i) mat[i][j]*=-1;
        sumcurent=0;
        sumpotential=0;
    }
    for (int i=0; i<m; ++i)
        for (int j=0; j<n; ++j)
            sum+=mat[i][j];

    g<<sumcur;
    return 0;
}