Pagini recente » Cod sursa (job #613379) | Cod sursa (job #372815) | Cod sursa (job #960284) | Cod sursa (job #2304724) | Cod sursa (job #249018)
Cod sursa(job #249018)
program fgs;
var
f:text;
a:array[1..16,1..16] of integer;
n,m,i,j:integer;
b:boolean;
procedure citire;
begin
assign(f,'flip.in');
reset(f);
readln(f,n,m);
for i:=1 to n do
begin
for j:=1 to m do
read(f,a[i,j]);
readln(f);
end;
close(f);
end;
function suli(c:integer):longint;
var
s:longint;
begin
s:=0;
for j:=1 to m do
s:=s+a[c,j];
suli:=s;
end;
function suco(c:integer):longint;
var
s:longint;
begin
s:=0;
for i:=1 to n do
s:=s+a[i,c];
suco:=s;
end;
function suma:longint;
var
s:longint;
begin
s:=0;
for i:=1 to n do
for j:=1 to m do
s:=s+a[i,j];
suma:=s;
end;
begin
citire;
b:false;
while not b do
begin
b:=true;
for j:=1 to m do
if suco(j)<0 then
begin
b:=false;
for i:=1 to n do
a[i,j]:=a[i,j]*(-1);
end;
for i:=1 to n do
begin
b:=false;
if suli(i)<0 then
for j:=1 to m do
a[i,j]:=a[i,j]*(-1);
end;
end;
assign(f,'flip.out');
rewrite(f);
write(f,suma);
close(f);
end.