Skip to main content

Questioons

 // #abba

#include <iostream>


#define ROW 5

#define COL 5

using namespace std;

int count = 0;

bool countIslands(int M[][COL],int visited[][COL] ,int i, int j)

{

    if( i<0 || j <0 || i>=ROW || j>=COL || visited[i][j]==1 || M[i][j]==0)

    {

        return false;

    }

    visited[i][j] = 1;

    bool a = countIslands(M,visited,i+1,j);

    bool b = countIslands(M,visited,i-1,j);

    bool c = countIslands(M,visited,i,j+1);

    bool d = countIslands(M,visited,i,j-1);

    bool e = countIslands(M,visited,i-1,j-1);

    bool f = countIslands(M,visited,i-1,j+1);

    bool g = countIslands(M,visited,i+1,j+1);

    bool h = countIslands(M,visited,i+1,j-1);

    

    if(!a && !b && !c && !d && !e && !f && !g && !h  )

    {

        

        count++;

        return true;

    }

    return a || b || c || d || e || f || g || h;


    

}


int main()

{

    int M[][COL] = { { 1, 1, 0, 0, 0 },

                     { 0, 1, 0, 0, 1 },

                     { 1, 0, 0, 1, 1 },

                     { 0, 0, 0, 0, 0 },

                     { 1, 0, 1, 0, 1 } };

                     

     int N[][COL] = { { 0, 0, 0, 0, 0 },

                     { 0, 0, 0, 0, 0 },

                     { 0, 0, 0, 0, 0 },

                     { 0, 0, 0, 0, 0 },

                     { 0, 0, 0, 0, 0 } };

     countIslands(M,N,0,0);

     for(int i = 0 ; i < ROW ; i++)

     {

         for(int j = 0 ; j < COL ; j++)

         {

             countIslands(M,N,i,j);

         }

     }

    cout << "Number of islands is: " << count;;

 

    return 0;

}

Comments

Popular posts from this blog

Story 1

 My Story Lorem Ipsum  is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.