You are on page 1of 2

program d405;

var solution : array[1..39] of char;


a, w, h, posx, posy, step : integer;
maze : array[1..20] of string[20];
begin
readln(h, w);
for a := 1 to h do
readln(maze[a]);
repeat
posx := 1;
posy := 1;
step := 1;
repeat
if maze[posy, posx + 1] = '.' then
begin
solution[step] := 'E';
step := step + 1;
posx := posx + 1;
end
else if maze[posy + 1, posx] = '.' then
begin
solution[step] := 'S';
step := step + 1;
posy := posy + 1;
end;
until ((posx = w) or (maze[posy, posx + 1] =
'#')) and ((posy = h) or (maze[posy + 1, posx] = '#'));
if (posx <> w) or (posy <> h) then
maze[posy, posx] := '#';

until (posx = w) and (posy = h);


for a := 1 to w + h - 2 do
write(solution[a]);
end.

You might also like