Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

I need the C code for this please The Problem Jill, the new lab assistant has ma

ID: 3680125 • Letter: I

Question

I need the C code for this please

The Problem

Jill, the new lab assistant has made new cages for the lab rabbits, Peter and Cottontail. Unfortunately, these new cages are more like mazes with walls in every direction. Help Arup determine if the rabbits are in the same section of the cage or different sections. Each rabbit can hop one square directly up, down, right or left. They can hop as many times as they want from one free square to another. Each rabbit must stay on the grid.

The Input

Each input will start with a single integer T (1 T 100) on the first line. The number T will denote the number of test cases that follow. Each test case will begin with two integers, R and C (1 R, C 10) separated by a space. Each of the next R lines will contain C characters of either ‘_’,’#’, ‘P’ or ‘C’ (Quotes for clarity). This will form a grid that represents the cage. A ‘_’ represents a cell free of obstructions, ‘#’ represents a wall, ‘P’ is Peter’s location and ‘C’ is Cottontail’s location. Each grid is guaranteed to have one and only one P and C.

The Output

For each test case output a single line containing “yes” if Peter and Cottontail are in the same section of the cage and “no” if they are not in the same section of the cage.

Sample Input Sample Output

4 no

2 2 yes

P# yes

#C no

2 2

P_

C_

8 7

__P____

####_##

_____#_

_____#C

##_###_

_____#_

___#_#_

___#___

5 7

__P____

####_##

_____#_

_____#C

##_###_

Explanation / Answer

package com.he.capillary;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class RabbitAndCages {

   static char[][] arr = null;
   static int[][] visited = null;

   public static void main(String[] args) throws IOException {

       BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
       String line = br.readLine();
       int testCases = Integer.parseInt(line);
       for (int i = 0; i < testCases; i++) {
           line = br.readLine();
           String str[] = line.trim().split(" ");
           int row = Integer.parseInt(str[0]);
           int col = Integer.parseInt(str[1]);
           arr = new char[row][col];
           visited = new int[row][col];
           int[] P = new int[2];
           int[] C = new int[2];
           for (int j = 0; j < row; j++) {
               String values[] = br.readLine().split("");
               for (int k = 0; k < col; k++) {
                   arr[j][k] = values[k].charAt(0);
                   if (arr[j][k] == 'P') {
                       P[0] = j;
                       P[1] = k;
                   } else if (arr[j][k] == 'C') {
                       C[0] = j;
                       C[1] = k;
                   }
               }
           }

           if (isReachable(P, C, visited, arr, P[0], P[1], row, col)) {
               System.out.println("yes");
           } else {
               System.out.println("no");
           }
       }
   }

   private static boolean isReachable(int[] P, int[] C, int visited[][], char arr[][], int i, int j, int row,
           int col) {
       boolean result = false;
       visited[i][j] = 1;
       if (i == C[0] && j == C[1]) {
           result = true;
           return result;
       }
       if (i + 1 < row && visited[i + 1][j] != 1 && arr[i + 1][j] != '#'
               && isReachable(P, C, visited, arr, i + 1, j, row, col)) {
           return true;
       }
       if (i - 1 > 0 && visited[i - 1][j] != 1 && arr[i - 1][j] != '#'
               && isReachable(P, C, visited, arr, i - 1, j, row, col)) {
           return true;
       }
       if (j + 1 < col && visited[i][j + 1] != 1 && arr[i][j + 1] != '#'
               && isReachable(P, C, visited, arr, i, j + 1, row, col)) {
           return true;
       }
       if (j - 1 > 0 && visited[i][j - 1] != 1 && arr[i][j - 1] != '#'
               && isReachable(P, C, visited, arr, i, j - 1, row, col)) {
           return true;
       }
       return result;
   }

}

I have written In java but didn't use any library functions simple Arrays. You can convert into "C" easily.