Cod sursa(job #665321)

Utilizator Dddarius95Darius-Florentin Neatu Dddarius95 Data 21 ianuarie 2012 22:20:47
Problema Iepuri Scor 0
Compilator fpc Status done
Runda Arhiva de probleme Marime 5.44 kb
program labirintiepure;
type mat=array[0..201,0..201] of -1..10;
var a:mat;ok,ok2:boolean;
    n,m,i,j,xi,yi,xf,yf,dir,morc,pas,nrt:integer;
    f,g:text;
procedure directie(i,j,dir:integer);
  var mor:integer;ok,ok2:boolean;
  begin
  ok:=true;ok2:=false;
  if dir=1 then while ok and(a[i,j]<>2)and(a[i,j]<>3)and(a[i,j]<>4) do
                        begin
                        dec(i);
                        if a[i,j]<>-1 then inc(pas)
                        else ok:=false;
                        if ok then xf:=i;
                        if a[i,j]=7 then begin inc(morc);a[i,j]:=0;end;
                        if morc=nrt then begin
                                         ok:=false;ok2:=true;xf:=i;
                                         end
                        else
                        begin
                        if (a[i,j]=2)or(a[i,j]=3)or(a[i,j]=4) then begin
                                                                   dir:=a[i,j];
                                                                   a[i,j]:=0;
                                                                   directie(i,j,dir);
                                                                   end;
                        end;
                        end;
   if dir=2 then while ok and(a[i,j]<>1)and(a[i,j]<>3)and(a[i,j]<>4) do
                        begin
                        dec(j);
                        if a[i,j]<>-1 then inc(pas)
                        else ok:=true;
                        if ok then yf:=j;
                        if a[i,j]=7 then begin inc(morc);a[i,j]:=0;end;
                        if morc=nrt then begin
                                         ok:=false;ok2:=true;yf:=j;
                                         end
                        else begin
                             if (a[i,j]=1)or(a[i,j]=3)or(a[i,j]=4) then
                                                             begin
                                                             dir:=a[i,j];
                                                             a[i,j]:=0;
                                                             directie(i,j,dir);
                                                             end;
                            end;
                        end;
   if dir=3 then while ok and(a[i,j]<>1)and(a[i,j]<>2)and(a[i,j]<>4) do
                        begin
                        inc(i);
                        if a[i,j]<>-1 then inc(pas)
                        else ok:=true;
                        if ok then xf:=i;
                         if a[i,j]=7 then begin inc(morc);a[i,j]:=0;end;
                         if morc=nrt then begin
                                         ok:=false;ok2:=true;xf:=i;
                                          end
                        else begin
                             if a[i,j]=-1 then ok:=false;

                             if (a[i,j]=1)or(a[i,j]=2)or(a[i,j]=4) then begin
                                                                   dir:=a[i,j];
                                                                   a[i,j]:=0;
                                                                   directie(i,j,dir);
                                                                   end;
                             end;
                        end;
    if dir=4 then while ok and(a[i,j]<>1)and(a[i,j]<>2)and(a[i,j]<>3) do
                        begin
                        inc(j);
                        if a[i,j]<>-1 then inc(pas)
                        else ok:=false;
                        if ok then yf:=j;
                        if a[i,j]=7 then begin inc(morc);a[i,j]:=0;end;
                        if morc=nrt then begin
                                         ok:=false;ok2:=true;yf:=j;
                                         end
                        else begin
                             if a[i,j]=-1 then ok:=false;

                             if (a[i,j]=1)or(a[i,j]=2)or(a[i,j]=3) then begin
                                                                   dir:=a[i,j];
                                                                   a[i,j]:=0;
                                                                   directie(i,j,dir);
                                                                   end;
                             end;
                        end;
  end;
procedure tipar(ok,ok2:boolean);
            begin
            if (ok=false)and ok2 then begin
                        writeln(g,'FERICIT');
                        writeln(g,xf,' ',yf);
                        writeln(g,nrt,' ',pas);
                        end;
            if (ok=false) and (ok2=false) then begin
                       writeln(g,'RATACIT');
                       writeln(g,xf,' ',yf);
                       writeln(g,morc,' ',pas);
                       end;
           end;
begin
assign(f,'iepure.in');reset(f);
assign(g,'iepure.out');rewrite(g);
readln(f,m,n);
readln(f,xi,yi,dir);
for i:=1 to m do
   begin
   for j:=1 to n do begin read(f,a[i,j]); if a[i,j]=7 then inc(nrt);end;
   readln(f);
   end;
for j:=0 to n+1 do a[0,j]:=-1;
for j:=0 to n+1 do a[m+1,j]:=-1;
for i:=0 to m+1 do a[i,0]:=-1;
for i:=0 to m+1 do a[i,n+1]:=-1;
morc:=0;pas:=0; xf:=xi;yf:=yi;
directie(xi,yi,dir);
tipar(ok,ok2);
{for i:=0 to m+1 do
   begin
   for j:=0 to n+1 do write(g,a[i,j]:3);
   writeln(g);
   end;    }
close(F);close(g);
end.