Question: Write code in C + + Also, check for the corner cases. There is a cleaning robot which is cleaning a rectangular grid of size
Write code in C Also, check for the corner cases. There is a cleaning robot which is cleaning a rectangular grid of size N x M represented by array R consisting of N strings. Rows are numbered from to Nfrom top to bottom and columns are numbered from to Mfrom left to right The robot starts cleaning in the topleft corner, facing rightwards. It moves in a straight line for as long as it can, ie while there is an unoccupied grid square ahead of it When it cannot move forward, it rotates degrees clockwise and tries to move forward again until it encounters another obstacle, and so on Dots in the array represent empty squares and Xs represent occupied squares ones the robot cannot move through Each square that the robot occupied at least once is considered clean. The robot moves indefinitely. Write a function: int solution vector &R; that, given an array R consisting of N strings, each of length M representing the grid, returns the number of clean squares. Examples: Given A X X X X your function should return rn Given A X X X X your function should return The robot starts at facing rightwards, and moves to where it turns due to the obstacle at Then it goes down from to where it changes direction again due to another obstacle. Next it goes left from to where it turns once because of the grid boundary, then it moves once and turns once more, which makes it stand again at position facing rightwards, just as at the beginning, which means it will now repeat the loop indefinitely. The total number of cleaned squares is Given A x X x your function should return rn Given A X X X your function should return Given A X X XXX your function should return Given A your function should return because there is only one square on the grid and it is cleaned in the first move. Assume that: N and M are integers within the rance : rn Given A your function should return because there is only one square on the grid and it is cleaned in the first move. Assume that: N and M are integers within the range ; topleft cell is empty; each string in R consists only of the following characters: andor X In your solution, focus on correctness. The performance of your solution will not be the focus of the assessment.
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
