Cod sursa(job #1067208)

Utilizator azkabancont-vechi azkaban Data 26 decembrie 2013 15:44:45
Problema Jocul Flip Scor 30
Compilator fpc Status done
Runda Arhiva de probleme Marime 1.74 kb
Program flip;
var A : array [1..100,1..16] of longint;
    i,j,n,m,aux :byte;
    s1,s2,suma:longint;
procedure coloana;
     begin
           for j:=1 to n do begin
                         for i:=1 to m do begin
                                                 s1:=s1+A[i,j];
                                                 s2:=s2+(A[i,j]*(-1));
                                           end;

                          if s2>s1 then
                                       for i:=1 to n do A[i,j]:=A[i,j]*(-1);
                         s1:=0; s2:=0;
                   end;
    end;
procedure rind;
   begin
          for i:=1 to n do begin
                         for j:=1 to m do begin
                                                 s1:=s1+A[i,j];
                                                 s2:=s2+(A[i,j]*(-1));
                                           end;

                          if s2>s1 then
                                       for j:=1 to m do A[i,j]:=A[i,j]*(-1);
                         s1:=0; s2:=0;
              end;
          end;
begin
    assign(input,'flip.in'); reset(input);
    assign(output,'flip.out'); rewrite(output);
    read(n,m);
    s1:=0;
    s2:=0;
    suma:=0;
    for i:=1 to n do
          for j:=1 to m do
               read(A[i,j]);

    if n>=m then  begin
                        coloana;
                        rind;
                   end
            else begin
                     aux:=n;
                     n:=m;
                     m:=aux;
                     rind;
                     coloana;
                     end;






for i:=1 to n do
        for j:=1 to n do suma:=suma+A[i,j];
   write(suma);
   close(input);
   close(output);

 end.