Cod sursa(job #133330)

Utilizator valytgjiu91stancu vlad valytgjiu91 Data 8 februarie 2008 11:48:05
Problema Rj Scor 0
Compilator fpc Status done
Runda Arhiva de probleme Marime 2.92 kb
{$M 65520,0,655360}
var  n,m,i,j,v1,v2,ni,nf:integer;
a,b:array[0..6,0..9]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 begin a[i,j+1]:=k; q:=false; end;
if a[i,j-1]=0 then begin a[i,j-1]:=k; q:=false; end;
if a[i+1,j]=0 then  begin a[i+1,j]:=k;q:=false; end;
if a[i-1,j]=0 then begin a[i-1,j]:=k; q:=false; end;
if a[i+1,j+1]=0 then begin a[i+1,j+1]:=k; q:=false; end;
if a[i-1,j+1]=0 then begin a[i-1,j+1]:=k; q:=false; end;
if a[i-1,j-1]=0 then begin a[i-1,j-1]:=k; q:=false; end;
if a[i+1,j-1]=0 then begin a[i+1,j-1]:=k; q:=false; end;
end;

procedure lee2(i,j:integer);
begin
if b[i,j+1]=0 then begin b[i,j+1]:=k; q:=false; end;
if b[i,j-1]=0 then begin b[i,j-1]:=k; q:=false; end;
if b[i+1,j]=0 then  begin b[i+1,j]:=k;q:=false; end;
if b[i-1,j]=0 then begin b[i-1,j]:=k; q:=false; end;
if b[i+1,j+1]=0 then begin b[i+1,j+1]:=k; q:=false; end;
if b[i-1,j+1]=0 then begin b[i-1,j+1]:=k; q:=false; end;
if b[i-1,j-1]=0 then begin b[i-1,j-1]:=k; q:=false; end;
if b[i+1,j-1]=0 then begin b[i+1,j-1]:=k; q:=false; 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;}
 i:=0;
     while Not eof(f) do
     begin
          i:=i+1; j:=0;
          while Not eoln(f) Do
          begin
              read(f,c);
              j:=j+1;
              case c of
                       'X': begin a[i,j]:=-1; b[i,j]:=-1; end;
                       ' ': begin a[i,j]:=0; b[i,j]:=0 end;
                       'R': a[i,j]:=1;
                       'J': b[i,j]:=1;
                end;
             end;
          Readln(f);
     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; b[i,0]:=-1;
  a[i,m+1]:=-1;b[i,m+1]:=-1;
  end;
for j:=0 to m+1 do
  begin
  a[0,j]:=-1;b[0,j]:=-1;
  a[n+1,j]:=-1;b[n+1,j]:=-1;
  end;
k:=1;
q:=false;
while q=false do
begin
q:=true;
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;

k:=1;
q:=false;
while q=false do
begin
q:=true;
k:=k+1;
for i:=1 to n do
for j:=1 to m do
if b[i,j]=k-1 then lee2(i,j);
end;
for i:=1 to n do
for j:=1 to m do
     if (a[i,j]=b[i,j]) and (a[i,j]>0) then begin
                           k:=a[i,j];
                           xf:=i;
                           yf:=j;
                           end;



assign(g,'rj.out');
rewrite(g);
if q then
          writeln(g,k,' ',xf,' ',yf);
close(g);
{for i:=1 to n do
begin
for j:=1 to m do
write(a[i,j],' ');
writeln;
end;}

end.