Cod sursa(job #1105008)

Utilizator floryn5Lungu Florin floryn5 Data 11 februarie 2014 12:48:23
Problema Jocul Flip Scor 20
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.75 kb
#include <iostream>
#include <fstream>
using namespace std;

int test2(int a[17][17], int n, int m)
{int i,j,po,ne,s=0;
for (i=0;i<n;i++)
{po=ne=0;
 for (j=0;j<m;j++)
   if (a[i][j]>0)
        po=po+a[i][j];
   else ne=ne+a[i][j];
ne=-ne;
if (ne>po)
    s=s+ne;
    else s=s+po;
}
return s;
}

int test1(int a[17][17], int n, int m)
{int i,j,po,ne;
for (i=0;i<n;i++)
{po=ne=0;
 for (j=0;j<m;j++)
   if (a[j][i]>0)
        po=po+a[j][i];
   else ne=ne+a[j][i];
ne=-ne;
if (ne>po)
    for (j=0;j<m;j++)
     a[j][i]=-a[j][i];
}
return test2(a,n,m);
}

int main()
{int n,m,a[17][17],i,j;
ifstream f("flip.in");
ofstream g("flip.out");
f>>n;f>>m;
for (i=0;i<n;i++)
    for (j=0;j<m;j++)
     f>>a[i][j];
g<<test1(a,n,m);
}