Cod sursa(job #249018)

Utilizator tferenc55takacs Ferenc tferenc55 Data 27 ianuarie 2009 12:09:12
Problema Jocul Flip Scor 0
Compilator fpc Status done
Runda Arhiva de probleme Marime 1.38 kb
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.