Question: Please write a code in c++ Given a m by n grids. Suppose that each cell has either an orange or it is empty. Some

Please write a code in c++

Please write a code in c++ Given a m by n grids.

Suppose that each cell has either an orange or it is empty.Some oranges are already rotten. An example is as follows, which shows

Given a m by n grids. Suppose that each cell has either an orange or it is empty. Some oranges are already rotten. An example is as follows, which shows a 4 by 5 grid with 6 oranges, 2 of which are rotten (red crossed). Every minute, any fresh orange that is adjacent (4-directionally) to a rotten orange becomes rotten. Assume that a fresh orange can only become rotten in this manner. The problem is to determine whether all of the oranges will eventually become rotten. And, if there are oranges that are not rotten, identify those oranges. For the above example, the answer is "Yes". The following shows that after 2 minutes, all the oranges become rotten. Minute 1 Minute 2 The following shows an example of a situation where there are some oranges that will never become rotten. Consider the top right most orange. In this case you the answer should be "No. Found not rotten oranges at: (1.5)". Note that you should list the coordinates of ALL the oranges that remain fresh. In this example, the only orange that remains fresh is the one at row 1 and column 5. Format of input: Read the input from file "input.txt". The first line of the file will contain two numbers separated by a space. The first number m is the number of rows, and the second number n is the number of columns. For the following m lines, each line corresponds to a row of a grid. Each row has n numbers separated by spaces. Each number corresponds to a cell of the row of the grid. If the number is 0, then it means the cell is empty. If it is 1, it means that it has a fresh orange. If it is 2, then it has a rotten orange. For example, the following file: 45 1 0001 1 2 100 00021 p The file represent the situation: co X Format of output: Output Yes or No. Found not rotten oranges at: " to the screen. The list of non-rotten oranges should be a list of pairs (X.X), where x is the row number of a non-rotten orange and y is the column number. Bonus Part: If you determine Yes", also try to output the minimum number of minutesthat must elapse until no cell has a fresh orange. For example, given Output: Yes. 2 (Because all oranges become rotten after 2 minutes.)

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!