Pagini recente » Cod sursa (job #335681) | Cod sursa (job #1672188) | Cod sursa (job #1862349) | Monitorul de evaluare | Cod sursa (job #1476973)
#include<iostream>
#include<fstream>
//#include<Windows.h>
using namespace std;
ifstream in;
ofstream out;
int main() {
unsigned short N, M;
long long int a[16][16], s1=0, s2=0, S=0, max=-1;
in.open ("flip.in");
in >> N >> M;
for (short i = 0; i < N; i++)
{
for (short j = 0; j < M; j++)
{
in >> a[i][j];
}
}
in.close();
for (short k = 0; k < 9;k++)
{
S = 0;
for (short i = 0; i < N; i++)
{
for (short j = 0; j < M; j++)
{
s1 += a[i][j];
s2 -= a[i][j];
}
if (s2 >= s1)
{
for (short j = 0; j < M; j++)
{
a[i][j] = -a[i][j];
}
}
s1 = 0;
s2 = 0;
}
for (short j = 0; j < M; j++)
{
for (short i = 0; i < N; i++)
{
s1 += a[i][j];
s2 -= a[i][j];
}
if (s2 >= s1)
{
for (short i = 0; i < N; i++)
{
a[i][j] = -a[i][j];
}
}
s1 = 0;
s2 = 0;
}
for (short i = 0; i < N; i++)
{
for (short j = 0; j < M; j++)
{
S += a[i][j];
}
}
if (max < S)
{
max = S;
}
}
/*for (short i = 0; i < N; i++)
{
for (short j = 0; j < M; j++)
{
cout << a[i][j] <<" ";
}
cout << "\n";
}
cout << "\n" << S <<"\n";
system("pause"); *\
out.open("flip.out");
out << S;
out.close();
}