Problem # 22 : Shortest Path (Maze)

Write a sub-routine MAZE which finds the shortest path between two points given in a two-dimension array of characters and also outputs the numbers of steps taken to reach the destination.
The program should accept the number of rows and columns in the maze and then input one of the following four characters into each element of the array :-

    | (signifying a wall in the maze)

    S (signifying the starting point in the maze)
    E (signifying the destination)
    - (signifying a blank space)

The path should then be displayed on the screen using '@'

There could be more than one way to reach the destination in the smallest number of steps.

Sample Output

This input
should generate the following output

Number of rows in the maze : 3
Number of columns in the maze : 3

---
-|-
S|E


 
  
@@@
@|@
S|E

Number of steps taken : 6

Number of rows in the maze : 6
Number of columns in the maze : 8

--------
--|||---
----|---
--|---|-
|-|||||-
 ---S|E--



 
 
--------
--|||---
-@@@|@@@
-@|@@@|@
|@|||||@
-@@S|E@@

Number of steps taken : 18

Previous Problem
Return to problems at The Vault
(Back to problems at The Vault )
Next Problem

LinkExchange
LinkExchange Member
1