Cod sursa(job #1836769)

Utilizator iulia_tarnaIulia Tarna iulia_tarna Data 28 decembrie 2016 17:30:39
Problema Jocul Flip Scor 0
Compilator fpc Status done
Runda Arhiva de probleme Marime 1.91 kb
Program flip;

 Type tabel=array [1..20,1..20] of longint;
 Type linie=array [1..20] of longint;
 Type coloana=array [1..20] of longint;

 Var

 f1,f2:text;
 t:tabel;
 l:linie;
 c:coloana;
 n,m,i,j,sl,sc,x,cc,cl,kl,kc,s:longint;

Begin

 Assign (f1,'flip.in');
 Reset  (f1);
 Assign (f2,'flip.out');
 Rewrite(f2);

 Readln (f1,n,m);

 s:=0;

           //citesc tablou si fac vectorul pentru linii

 For i:=1 to n do

        Begin

        For j:=1 to m do

                Begin

                Read (f1,t[i,j]);
                l[i]:=l[i]+t[i,j];

                end;
       readln(f1);
       end;

        //sfirsit

        //aflu cel mai mic nr din tablou

 kl:=l[1];

 For i:=1 to n do

        Begin

        If l[i]<kl then
        kl:=l[i];

        end;

        //sfirsit

        //aflu ce linie este

 For x:=1 to n do

        Begin

        If l[x]=kl then
        cl:=x;

        end;

        //fac vectorul pentru coloane

 For j:=1 to m do

        Begin

        For i:=1 to n do

                Begin

                c[j]:=t[i,j]+c[j];

                end;
        end;

        //sfirsit

        //aflu cel mai mic numar din vectorul pentru colana

 kc:=c[1];

 For x:=1 to m do

        Begin

        If c[x]<kc then
        kc:=c[x];

        end;

        //sfirsit

        //aflu ce coloana este

 For x:=1 to n do

        Begin

        If c[x]=kc then
        cc:=x;

        end;

        //sfirsit

        //schimb valoarea numerelor care trebuie si aflu suma
 For i:=1 to n do

        Begin

        For j:=1 to m do

                Begin

                If i=cl then t[i,j]:=t[i,j]*(-1);
                If j=cc then t[i,j]:=t[i,j]*(-1);
                s:=s+t[i,j];

                end;

        end;


        //sfirsit

 Writeln (f2,s);

 Close (f1);
 Close (f2);
end.