Cod sursa(job #1720674)

Utilizator alexthebest08Alex Alex alexthebest08 Data 23 iunie 2016 00:09:09
Problema Jocul Flip Scor 30
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.99 kb
#include <iostream>
#include <fstream>

using namespace std;

int main()
{
    int n,m,a[16][16],i,j,sum_col,sum_line,sum_total=0;

    ifstream f1 ("flip.in");
    ofstream f2 ("flip.out");

    f1 >> n >> m;

    for (i=0;i<n;i++)
        for (j=0;j<m;j++)
            f1 >> a[i][j];

    for (j=0;j<m;j++){
            sum_col = 0;
        for (i=0;i<n;i++)
            sum_col = sum_col + a[i][j];
           if (sum_col < 0)
           {
               for (i=0;i<n;i++)
                  a[i][j] = a[i][j] * (-1);
           }
    }

    for (i=0;i<n;i++){
            sum_line = 0;
        for (j=0;j<m;j++)
            sum_line = sum_line + a[i][j];
           if (sum_line < 0)
           {
               for (j=0;j<m;j++)
                  a[i][j] = a[i][j] * (-1);
           }
    }

    for (i=0;i<n;i++)
        for (j=0;j<m;j++)
           sum_total = sum_total + a[i][j];

    f2 << sum_total;

    f1.close();
    f2.close();

    return 0;

}