Cod sursa(job #2363979)

Utilizator Ilie_MityIlie Dumitru Ilie_Mity Data 3 martie 2019 19:38:22
Problema Jocul Flip Scor 20
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.89 kb
#include <cstdio> //Ilie Dumitru

using namespace std;

int main()
{
    int n,m,mat[16][16],s[16],sc[16],i,j,stot;
    FILE *f,*g;
    f=fopen("flip.in", "r");
    fscanf(f,"%i",&n);
    fscanf(f,"%i",&m);
    for(i=0;i<n;i++)
    {
        s[i]=0;
        for(j=0;j<m;j++)
        {
            fscanf(f, "%i", &mat[i][j]);
            s[i]+=mat[i][j];
        }
    }
    fclose(f);
    for(i=0;i<n;i++)
        if(s[i]<0)
            for(j=0;j<m;j++)
                mat[i][j]*=-1;
    for(j=0;j<m;j++)
    {
        sc[j]=0;
        for(i=0;i<n;i++)
            sc[j]+=mat[i][j];
    }
    for(j=0;j<m;j++)
        if(sc[j]<0)
            for(i=0;i<n;i++)
                mat[i][j]*=-1;
    stot=0;
    for(i=0;i<n;i++)
        for(j=0;j<m;j++)
            stot+=mat[i][j];
    g=fopen("flip.out","w");
    fprintf(g, "%i", stot);
    fclose(g);
    return 0;
}