Cod sursa(job #1748764)

Utilizator horiacoolNedelcu Horia Alexandru horiacool Data 26 august 2016 19:30:09
Problema Jocul Flip Scor 30
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.11 kb
#include <iostream>
#include <fstream>
using namespace std;
ifstream f("flip.in");
ofstream g("flip.out");
int N,M,i,j,mat[100][100],s1,s2,S1,S2;

void Read()
{
    f>>N>>M;
    for(i=1;i<=N;i++)
        for(j=1;j<=M;j++)
            f>>mat[i][j];

}

int suma_matrice(int x)
{
    x=0;

    for(i=1;i<=N;i++)
    {
        s1=0;
        s2=0;
        for(j=1;j<=M;j++)
            {
            s1=s1+mat[i][j];
            s2=s2-mat[i][j];
            }
        if(s1<s2)
            for(j=1;j<=M;j++)
                mat[i][j]=mat[i][j]*(-1);
    }
    for(j=1;j<=M;j++)
    {
        s1=0;
        s2=0;
        for(i=1;i<=N;i++)
            {
            s1=s1+mat[i][j];
            s2=s2-mat[i][j];
            }
        if(s1<s2)
            for(i=1;i<=N;i++)
                mat[i][j]=mat[i][j]*(-1);
    }
    for(i=1;i<=N;i++)
        for(j=1;j<=M;j++)
           x=x+mat[i][j];

    return x;

}

int main()
{

   Read();
   S1=0;
   S2=1;

   while(S1<S2)
    {
      S1=suma_matrice(S1);
      S2=suma_matrice(S2);
    }

   g<<S1;

  return 0;
}