0% found this document useful (0 votes)
134 views

Assignment 12

The document describes an assignment to write a program that can navigate a maze from a starting point (#) to the library entrance (@) by only moving between empty cells marked with 1s, with the maze layout and valid path provided as input. The input specifies the number of rows and columns of the maze as well as each cell marked as 0 for solid or 1 for empty, and the program must output the number of moves required to reach the entrance. Sample inputs and outputs are provided to demonstrate the expected format.

Uploaded by

dharm_dare
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
134 views

Assignment 12

The document describes an assignment to write a program that can navigate a maze from a starting point (#) to the library entrance (@) by only moving between empty cells marked with 1s, with the maze layout and valid path provided as input. The input specifies the number of rows and columns of the maze as well as each cell marked as 0 for solid or 1 for empty, and the program must output the number of moves required to reach the entrance. Sample inputs and outputs are provided to demonstrate the expected format.

Uploaded by

dharm_dare
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 1

Assignment: 12

Escape from Maze


NCST has decided to create a maze, next to it's library, so that only intelligent people can go into the library. As is typical of mazes, this one too has several dead ends and only one correct start and end point. You have to write a program to navigate this maze and enter the library. Your starting point in the maze is marked by the character '#' and the entrance to the library (i.e., end point of the maze) is marked by the character '@', i.e. your program must start from '#' and end at '@'. The maze is composed of a rectangular array of cells. Apart from the start (#) and end (@) cells, maze contains solid cells and empty cells. A valid path never passes via a solid cell. The solid cells are marked by 0s and empty cells are marked by 1s. Once on a cell, you can only move to any one of the neighbouring four (i.e., north, east, west, south) cells. Note: Assume that no path will ever cross itself, i.e., there will be no loops in any path.

Input specification:
The first line of input will be two integers, R and C, specifying the number of rows and columns. The next R lines contain C characters each separated by white space, thereby specifying the layout of the maze. It is guaranteed that the maze will contain only one starting and one ending character. Also, it is guaranteed that the maze will contain only one correct path, from the start point to the end point.

Output specification:
Your program must output on one line, the number of hops required to reach the end point.

Sample Input and Output:


Input: 5 5 0 0 0 0 0 0 0 0 0 # @ 0 0 0 0 0 0 0 0 0 Output: 1 0 0 0 0 0 Input: 6 6 0 0 0 0 0 1 0 1 1 1 1 1 0 1 0 1 0 0 # 1 0 1 1 0 Output: 6 @ 1 0 0 1 0 0 0 1 0 1 1

You might also like