Guest User

Untitled

a guest
Jan 23rd, 2018
103
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pascal 3.06 KB | None | 0 0
  1. program Project1;
  2.  
  3. {$APPTYPE CONSOLE}
  4.  
  5. uses
  6.   SysUtils;
  7.  
  8. var
  9.   N, M, i, j, sveti, svetj: integer;
  10.   Lab: array[1..1000,1..1000] of Char;
  11.  
  12. procedure svet_go(i, j, di, dj: integer);
  13. var
  14.   curi, curj: integer;
  15. begin
  16. if not ((Lab[i+di, j]='*') and (Lab[i, j+dj]='*')) then
  17.   begin
  18.   if (i+di>0) and (i+di<N+1) then curi:=i+di else begin curi:=i; di:=-di; end;
  19.   if (j+dj>0) and (j+dj<M+1) then curj:=j+dj else begin curj:=j; dj:=-dj; end;
  20.   if (Lab[curi, curj]<>'*') and (Lab[curi, curj]<>'X') then
  21.         begin
  22.         if (di*dj>0) and (Lab[curi, curj]='.') then Lab[curi, curj]:='\';
  23.         if (di*dj>0) and (Lab[curi, curj]='/') then Lab[curi, curj]:='X';
  24.         if (di*dj<0) and (Lab[curi, curj]='.') then Lab[curi, curj]:='/';
  25.         if (di*dj<0) and (Lab[curi, curj]='\') then Lab[curi, curj]:='X';
  26.         svet_go(curi, curj, di, dj);
  27.         end;
  28.   if Lab[curi, curj]='*' then begin
  29.                               if (Lab[curi-di, curj]='*')  and (Lab[curi, curj-dj]<>'*') then
  30.                                   begin
  31.                                   curj:=curj-dj;
  32.                                   dj:=-dj;
  33.                                   if (di*dj>0) and (Lab[curi, curj]='.') then Lab[curi, curj]:='\';
  34.                                   if (di*dj>0) and (Lab[curi, curj]='/') then Lab[curi, curj]:='X';
  35.                                   if (di*dj<0) and (Lab[curi, curj]='.') then Lab[curi, curj]:='/';
  36.                                   if (di*dj<0) and (Lab[curi, curj]='\') then Lab[curi, curj]:='X';
  37.                                   svet_go(curi, curj, di, dj);
  38.                                   end;
  39.                               if (Lab[curi-di, curj]<>'*') and (Lab[curi, curj-dj]='*') then
  40.                                   begin
  41.                                   curi:=curi-di;
  42.                                   di:=-di;
  43.                                   if (di*dj>0) and (Lab[curi, curj]='.') then Lab[curi, curj]:='\';
  44.                                   if (di*dj>0) and (Lab[curi, curj]='/') then Lab[curi, curj]:='X';
  45.                                   if (di*dj<0) and (Lab[curi, curj]='.') then Lab[curi, curj]:='/';
  46.                                   if (di*dj<0) and (Lab[curi, curj]='\') then Lab[curi, curj]:='X';
  47.                                   svet_go(curi, curj, di, dj);
  48.                                   end;
  49.                               end;
  50.   end;
  51.  
  52. end;
  53.  
  54. begin
  55.  
  56. readln(N, M);
  57. for i:=1 to N do for j:=1 to M do begin
  58.                                   if j<>M then read(Lab[i,j]) else readln(Lab[i,j]);
  59.                                   if Lab[i,j]='X' then begin
  60.                                                        sveti:=i;
  61.                                                        svetj:=j;
  62.                                                        end;
  63.                                   end;
  64.  
  65. svet_go(sveti, svetj, 1, 1);
  66. svet_go(sveti, svetj, 1, -1);
  67. svet_go(sveti, svetj, -1, 1);
  68. svet_go(sveti, svetj, -1, -1);
  69.  
  70.  
  71. writeln;
  72. for i:=1 to N do for j:=1 to M do if j<>M then write(Lab[i,j]) else writeln(Lab[i,j]);
  73.  
  74. readln;
  75. end.
Add Comment
Please, Sign In to add comment