Answer to Question #286970 in C for Rupa

Question #286970

The following is a two-dimensional character array of size 12X12 which represents a maze. The symbol ‘#’ represent a wall of the maze and the symbol ‘.’ represents a possible path. There is an entry point and exit point of the maze, which are denoted by a ‘.’ Write a C program which takes text file which contains the maze as command line argument and prints the minimum number of moves required to go from entry to exit. If there is no path from entry to exit display “-1”. You need to formulate the maze as a graph and use Breadth First Search to find shortest path from entry to exit. You can treat each cell as a vertex and if we can go from one cell to other cell with one move add edge between the corresponding vertices. For example, for the below maze:

############

. . . ##. ##. . .# 

##. . . . . . . .## 

#. .######. ##

####. . . . . . .#

# . . . .#. ###.#

###. . . . . . . .#

#. . .######. #

#####. . .#. .#

#. . .#. #. #. ##

#.#. . .#. . . . .

############

Min moves: 22 


1
Expert's answer
2022-01-13T03:57:01-0500
#include<conio.h>
#include <iostream>
#include<stdio.h>
#include<stdlib.h>
#include<time.h>
#include <cmath>
#include<dos.h>
#include <bits/stdc++.h> 
#include<vector>
using namespace std;


#define ROW	5
#define COL	5


int main()
{
	char maze[ROW][COL] ={
							{'#','-','#','#'},
							{'-','#','-','#'},
							{'#','-','-','#'},
							{'-','#','-','#'},
							{'#','-','-','#'},							
						};
	int r,c;
	cout<<"\n\tMaze\n";
	for(r=0;r<ROW;r++)	
	{
		for(c=0;c<COL;c++)
		{
			cout<<"\t"<<maze[r][c];
		}
		cout<<endl;
	}
	return(0);
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS