Cod sursa(job #132594)

Utilizator valytgjiu91stancu vlad valytgjiu91 Data 6 februarie 2008 10:49:37
Problema Rj Scor 0
Compilator fpc Status done
Runda Arhiva de probleme Marime 2.42 kb
var  n,m,i,j,v1,v2,ni,nf:integer;
a:array[0..101,0..101]of integer;
c:char;
f,g:text;
k,xf,yf,p,u,v:integer;
q:boolean;
procedure lee(i,j:integer);
begin
if a[i,j+1]=0 then a[i,j+1]:=k
              else if a[i,j+1]=k then begin q:=true; xf:=i; yf:=j+1; end;
if a[i,j-1]=0 then a[i,j-1]:=k
                else if a[i,j-1]=k then begin q:=true; xf:=i; yf:=j-1; end;
if a[i+1,j]=0 then a[i+1,j]:=k
               else if a[i+1,j]=k then begin q:=true; xf:=i+1; yf:=j; end;
if a[i-1,j]=0 then a[i-1,j]:=k
               else if a[i-1,j]=k then begin q:=true; xf:=i-1; yf:=j; end;
if a[i+1,j+1]=0 then a[i+1,j+1]:=k
                 else if a[i+1,j+1]=k then begin q:=true; xf:=i+1; yf:=j+1; end;
if a[i-1,j+1]=0 then a[i-1,j+1]:=k
                else if a[i-1,j+1]=k then begin q:=true; xf:=i-1; yf:=j+1; end;
if a[i-1,j-1]=0 then a[i-1,j-1]:=k
                 else if a[i-1,j-1]=k then begin q:=true; xf:=i-1; yf:=j-1; end;
if a[i+1,j-1]=0 then a[i+1,j-1]:=k
                 else if a[i+1,j-1]=k then begin q:=true; xf:=i+1; yf:=j-1; end;
end;
begin
assign(f,'rj.in');
reset(f);
readln(f,n,m);
for i:=1 to n do
     begin
          for j:=1 to m do
          begin
              read(f,c);
              case c of
                       'x': a[i,j]:=-1;
                       ' ': a[i,j]:=0;
                       'R': a[i,j]:=1;
                       'J': a[i,j]:=1;
                end;
             end;
          readln(f);
     end;

{for i:=1 to n do
for j:=1 to m do
begin
read(f,a[i,j]);
{if c='x' then a[i,j]:=-1
         else if c=' ' then a[i,j]:=0
            else if  c='R' then a[i,j]:=1
                            else begin
                                jx:=i;
                                jy:=j;
                             if c='J' then  a[i,j]:=1;}
  { case c of
                       'x': a[i,j]:=-1;
                       ' ': a[i,j]:=0;
                       'R': a[i,j]:=1;
                       'J': a[i,j]:=0;
              end;
end;}
for i:=1 to n do
begin
for j:=1 to m do
write(a[i,j],' ');
writeln;
end;
for i:=0 to n+1 do
  begin
  a[i,0]:=-1;
  a[i,m+1]:=-1;
  end;
for j:=0 to m+1 do
  begin
  a[0,j]:=-1;
  a[n+1,j]:=-1;
  end;
k:=1;
q:=false;
while q=false do
begin
k:=k+1;
for i:=1 to n do
for j:=1 to m do
if a[i,j]=k-1 then lee(i,j);
end;
assign(g,'rj.out');
rewrite(g);
if q then
          writeln(g,k,' ',xf,' ',yf);
close(g);
end.