The world’s Largest Sharp Brain Virtual Experts Marketplace Just a click Away
Levels Tought:
Elementary,Middle School,High School,College,University,PHD
| Teaching Since: | May 2017 |
| Last Sign in: | 406 Weeks Ago, 2 Days Ago |
| Questions Answered: | 66690 |
| Tutorials Posted: | 66688 |
MCS,PHD
Argosy University/ Phoniex University/
Nov-2005 - Oct-2011
Professor
Phoniex University
Oct-2001 - Nov-2016
Balin is stuck in a labyrinth beneath the lonely mountain and roof is about to collapse. Add a fire breathing dragon to the mix and it’s safe to say that he is desperate to get out of there as quickly as possible. Your task is to help him find the path to get out this pickle!
The labyrinth is represented as a m-by-n matrix with Balin’s position marked as ‘s’ and the exit marked as ‘f’. Cells are marked either as ‘b’ or ‘w’. The ‘w’ marked cells represent traps in the labyrinth, designed to kill and so Balin cannot choose those cells in his path to get out. The only safe positions are the ones that are marked with b’s. Your program must output the matrix containing ‘b’ in each cell on the required path and ‘-‘ (ASCII Code 45) in the other cells. In case there is no way for Balin to survive, output “The path doesn’t exist.”.
There is only one path to come out of the labyrinth but the labyrinth contains false paths which Balin must avoid because they will eventually lead to a trap.
The first line of the input will consist of an integer t representing the number of testcases.
Every testcase consists of the following lines:
The first line contains two integers n and m representing the number of rows and columns respectively.
Next n lines contain m letters denoting the map of the labyrinth.
For each testcase output an n X m matrix that has ‘s’, ‘f’ at the same positions as in the input matrix and a path represented by b’s which is path from s to f and for all other positions output a ‘–‘.
If no such path exists, output "The path doesn't exist." (quotes only for clarity).
NOTE: Balin cannot move diagonally
1
2
Input: 2 6 5 bbbbw bwwfw bbbww bwwww bbbbw wwwbs 4 4 bbbw wwfw bwww bbbs Output:
bbbb- b--f- b---- b---- bbbb- ---bs The path doesn't exist.
Hel-----------lo -----------Sir-----------/Ma-----------dam-----------Tha-----------nk -----------You----------- fo-----------r u-----------sin-----------g o-----------ur -----------web-----------sit-----------e a-----------nd -----------and----------- ac-----------qui-----------sit-----------ion----------- of----------- my----------- po-----------ste-----------d s-----------olu-----------tio-----------n.P-----------lea-----------se -----------pin-----------g m-----------e o-----------n c-----------hat----------- I -----------am -----------onl-----------ine----------- or----------- in-----------box----------- me----------- a -----------mes-----------sag-----------e I----------- wi-----------ll