Pagini recente » Rating Crutoi Alexandru (BurnScopesAli) | Cod sursa (job #2050313) | Cod sursa (job #2600333) | Cod sursa (job #2377892) | Cod sursa (job #1426547)
#include <iostream>
#include <fstream>
using namespace std;
void citire(int &N,int &M,int matrice[][20])
{
ifstream f("flip.in");
f>>N>>M;
for(int i=0;i<N;i++)
for(int j=0;j<M;j++)
f>>matrice[i][j];
f.close();
}
int suma(int N,int M,int matrice[][20])
{
int s=0;
for(int i=0;i<N;i++)
for(int j=0;j<M;j++)
s+=matrice[i][j];
return s;
}
void comuta(int N,int M,int matrice[][20],int i,int j)
{
for(int k=0;k<N;k++)
matrice[k][j]*=-1; //
for(int k=0;k<M;k++)
matrice[i][k]*=-1;
}
int suma_maxima(int N,int M,int matrice[][20])
{
int smax=0;
for(int i=0;i<N;i++)
for(int j=0;j<M;j++)
{
comuta(N,M,matrice,i,j);
int s=suma(N,M,matrice);
if(s<smax){
comuta(N,M,matrice,i,j);
}
else{
smax=s;
}
}
return smax;
}
void afisare(int N,int M,int a[][20])
{
for(int i=0;i<N;i++)
{
for(int j=0;j<M;j++)
cout<<a[i][j]<<' ';
cout<<endl;
}
cout<<endl;
}
int main()
{
int N,M,matrice[20][20];
citire(N,M,matrice);
ofstream g("flip.out");
g<<suma_maxima(N,M,matrice);
comuta(N,M,matrice,0,0);
afisare(N,M,matrice);
g.close();
}