Cod sursa(job #3152290)

Utilizator teo16Teo Manoiu teo16 Data 24 septembrie 2023 15:33:44
Problema Jocul Flip Scor 20
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 1.34 kb
#include <iostream>
#include<fstream>
#include<cmath>


using namespace std;

int main()
{
    ifstream f("flip.in");
    ofstream g("flip.out");
    int N,M,x, a[10000][17],i,j,s,t;
    f>>N>>M;
    for(i=1;i<=N;i++)
    {
        for(j=1;j<=M;j++)
        {
            f>>x;
            a[i][j]=x;
        }
    }
    for(i=1;i<=N;i++)
    {   s=0;
        t=0;
        for(j=1;j<=M;j++)
        {
            if(a[i][j]<0)
            {
                s=s+abs(a[i][j]);

            }
            else
            {
                t=t+a[i][j];
            }
        }
        if(s>t)
        {
            for(j=1;j<=M;j++)
            {
                a[i][j]=a[i][j]*(-1);
            }
        }

    }
    for(j=1;j<=M;j++)
    {
        s=0;
        t=0;
        for(i=1;i<=N;i++)
        {
            if(a[i][j]<0)
            {
                s=s+abs(a[i][j]);
            }
            else
            {
                t=t+a[i][j];
            }
        }
        if(s>t)
        {
            for(i=1;i<=N;i++)
            {
                a[i][j]=a[i][j]*(-1);
            }
        }
    }
    s=0;
    for(i=1;i<=N;i++)
    {
        for(j=1;j<=M;j++)
        {
            s=s+a[i][j];
        }
    }
    g<<s;
    f.close();
    g.close();



    return 0;
}