WAY.PAS 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. uses CRT;
  2. const
  3. XS = 10;
  4. YS = 10;
  5. var
  6. Lab : array [0..YS+1,0..XS+1] of byte;
  7. Out : array [1..YS,1..XS] of char;
  8. inp,outp : text;
  9. i,j : byte;
  10. buf : string;
  11. StX,StY,EnX,EnY : byte;
  12. Procedure WrB;
  13. begin
  14. write('É');
  15. FOR j := 1 to XS do write('Í');
  16. writeln('»');
  17. FOR i := 1 to YS do
  18. begin
  19. write('º');
  20. for j := 1 to XS do Write(out[i,j]);
  21. writeln('º');
  22. end;
  23. write('È');
  24. FOR j := 1 to XS do write('Í');
  25. write('¼');
  26. end;
  27. procedure SetNums(x,y,ch : byte);
  28. begin
  29. if (lab[y,x] <= ch) and (lab[y,x]<>0) then exit;
  30. if lab[y,x] = 1 then exit;
  31. lab[y,x] := ch;
  32. if X < XS then SetNums(x+1,y,ch+1);
  33. if Y < YS then SetNums(x,y+1,ch+1);
  34. if X > 1 then SetNums(x-1,y,ch+1);
  35. if Y > 1 then SetNums(x,y-1,ch+1);
  36. end;
  37. begin
  38. clrscr;
  39. assign(inp,'input.txt');reset(inp);
  40. fillchar(lab,XS*YS,255);
  41. for j := 1 to YS do
  42. begin
  43. ReadLn(inp,buf);
  44. for i := 1 to XS do Lab[j,i] := ord(buf[i])-$30;
  45. end;
  46. ReadLn(inp,StX,StY,EnX,EnY);
  47. if (StX=EnX) and (STY=EnY) then Begin WriteLn('Œ àèàãâ ¯ãáâ!'); Halt(255);end;
  48. for i := 1 to YS do for j:=1 to XS do if lab[i,j] = 1 then out[i,j] := 'Û';
  49. SetNums(StX,StY,2);
  50. i := enX;
  51. j := enY;
  52. while (i <> stX) or (j<>stY) do
  53. begin
  54. if lab[j+1,i] = lab[j,i]-1 then begin out[j,i] := #24;inc(j);Continue;end;
  55. if lab[j,i+1] = lab[j,i]-1 then begin out[j,i] := #27;inc(i);Continue;end;
  56. if lab[j-1,i] = lab[j,i]-1 then begin out[j,i] := #25;dec(j);Continue;end;
  57. if lab[j,i-1] = lab[j,i]-1 then begin out[j,i] := #26;dec(i);Continue;end;
  58. WriteLn('‚ë室  �…’!');
  59. Halt(255);
  60. end;
  61. out[j,i] := 'S';
  62. out[enY,enX] := 'F';
  63. WrB;
  64. WriteLn;
  65. WriteLn;
  66. ReadKey;
  67. end.