Cod sursa(job #1587330)

Utilizator DoubleNyNinicu Cristian DoubleNy Data 1 februarie 2016 22:21:38
Problema Jocul Flip Scor 10
Compilator fpc Status done
Runda Arhiva de probleme Marime 1.65 kb
type tabel=array[1..100,1..100] of longint;
  var a:tabel;
      i,j,n,m,suma : integer;
procedure flips(var fl:tabel);
 var turn:boolean;
     neg,poz:integer;
 begin
   i:=1;
   neg:=0;
   poz:=0;
   repeat

    for j:=1 to m do
     if fl[i,j]<0 then inc(neg)
     else if fl[i,j]>0 then inc(poz);
     if neg>poz then for j:=1 to m do
     fl[i,j]:=fl[i,j]*(-1);
     neg:=0; poz:=0;
     inc(i);

   until i=n+1;

    j:=1;
   neg:=0;
   poz:=0;
   repeat

    for i:=1 to n do
     if fl[i,j]<0 then inc(neg)
     else if fl[i,j]>0 then inc(poz);
     if neg>poz then for i:=1 to n do
     fl[i,j]:=fl[i,j]*(-1);
     neg:=0; poz:=0;
     inc(j);

   until j=m+1;

  poz:=0;
  neg:=0;
  i:=1;
  repeat

   for j:=1 to m do
    if fl[i,j]<0 then neg:=neg+fl[i,j]
    else if fl[i,j]>0 then poz:=poz+fl[i,j];
    if abs(neg)>poz then
    for j:=1 to m do fl[i,j]:=fl[i,j]*(-1);

    neg:=0; poz:=0;
    inc(i);
  until i=n+1;

  poz:=0;
  neg:=0;
  j:=1;
  repeat

   for i:=1 to n do
    if fl[i,j]<0 then neg:=neg+fl[i,j]
    else if fl[i,j]>0 then poz:=poz+fl[i,j];
    if abs(neg)>poz then
    for i:=1 to n do fl[i,j]:=fl[i,j]*(-1);

    neg:=0; poz:=0;
    inc(j);
  until j=m+1;

 end;

Begin
 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);
  flips(a);
 { for i:=1 to n do
   begin
    for j:=1 to m do   write(a[i,j],' ');
    writeln;
   end;  }
 assign(output,'flip.out'); rewrite(output);
 suma:=0;
 for i:=1 to n do
  for j:=1 to m do suma:=suma+a[i,j];
  write(output,suma);
  close(output);
end.