Cod sursa(job #1585442)

Utilizator DoubleNyNinicu Cristian DoubleNy Data 30 ianuarie 2016 23:59:06
Problema Jocul Flip Scor 10
Compilator fpc Status done
Runda Arhiva de probleme Marime 1.33 kb
program flip;
 var suma,n,m,i,j,k:integer;
     a:array[1..16,1..16] of integer;


 procedure control;
  var sumaNrNegative,sumaNrPozitive:integer;
  begin
   sumaNrNegative:=0;
   sumaNrPozitive:=0;
   for i:=1 to n do
    begin
      for j:=1 to m do
       if a[i,j]<0 then sumaNrNegative:=sumaNrNegative+a[i,j]
       else if a[i,j]>0 then sumaNrPozitive:=sumaNrPozitive+a[i,j];

       if abs(sumaNrNegative)>sumaNrPozitive then
        for k:=1 to m do a[i,k]:=a[i,k]*(-1);
      sumaNrNegative:=0;
      sumaNrPozitive:=0;
    end;

   for j:=1 to m do
    begin
      for i:=1 to n do
       if a[i,j]<0 then sumaNrNegative:=sumaNrNegative+a[i,j]
       else if a[i,j]>0 then sumaNrPozitive:=sumaNrPozitive+a[i,j];

       if abs(sumaNrNegative)>sumaNrPozitive then
        for k:=1 to n do a[k,j]:=a[k,j]*(-1);
        sumaNrNegative:=0;
        sumaNrPozitive:=0;
    end;



  end;



begin
 suma:=0;
 assign(input,'flip.in'); reset(input);
 readln(input,n,m);
 for i:=1 to n do
  for j:=1 to m do read(input,a[i,j]);
 close(input);
  control;
 { for i:=1 to n do
   begin
    for j:=1 to m do write(a[i,j],' ');
    writeln;
   end;
 writeln; }
 for i:=1 to n do
  for j:=1 to m do
   suma:=suma+a[i,j];
 assign(output,'flip.out'); rewrite(output);
 write(output,suma);
 close(output);
end.