how to count the rectangles with the same char in the field?

by מחמוד עראבי   Last Updated June 13, 2019 08:26 AM

in the question they ask to count how rectangle with the same char , and i cant count the char twice , and all the dots is mean empty like there is no char. and the field is given in the question and we dont get char from the user just what given in the question. for example the result of char ? is 2

#include<stdio.h>
#include<stdlib.h>
#include<math.h>
#include<conio.h>
#define M 12
#define N 8
char field[N][M] = { { '#','#','#','.','.','.','?','?','.','.','+','.' }
        ,{ '#','#','#','.','=','.','?','?','.','.','+','.' },
        { '#','#','#','.','.','.','.','.','.','.','+','.' },
        { '.','.','.','.','.','?','?','?','.','.','.','.' },
        { '?','?','?','.','.','?','?','?','.','.','=','=' },
        { '?','.','?','.','.','.','.','.','.','.','=','=' },
        { '?','?','?','.','+','+','+','.','.','.','.','.' },
        { '?','?','?','.','+','+','+','.','#','#','.','#' } };
void check_field(char field[][M])
{
    int i, j;
    for ( i = 0; i < N; i++)
    {
        for ( j = 0; j < M; j++)
        {
            if (field[i][j] != '.')
                if (find_char(field, &i, &j, field[i][j]))
                    add_count_func(field[i][j]);
        }
    }
}
void add_count_func(char ch)
{
    int row, col;
    int k;
    char field[N][M];
    int sum = 0, flag = 0,cnt1=0,cnt2=0;
    if (field[row][col] == ch)
    {
        cnt1++;// counting the width
        flag = 1;
        if (field[col][row] == ch)
        {
            cnt2++;//counting the hight
        }
    }[enter image description here][1]
    else if(flag=1)
    {
        if (field[N - 1][M - 1] == ch)
        {
            cnt1++; // it dosnt matter if its cnt1 or cnt2 cause its 1x1 rectangle
            cnt2 = cnt1;
        }
        if (field[N - 1][col] == ch)
        cnt1++; // cunting width of rectangle if its found in the last line.
    }

}
//function to find char if we dont return 0, else 1;
int find_char(char field[][M], int row, int col, char ch)
{
    if (field[row][col]==ch)
        return 1;
    return 0;
}
// function to print the given field.
: https://i.stack.imgur.com/u3409.png
Tags : java c++ c


Related Questions


Updated January 09, 2018 04:26 AM

Updated November 04, 2017 02:26 AM

Updated November 17, 2018 17:26 PM