Question

How can i find a algorithm that count numbers of a specific character in a matrix? Im thinking a DFS?

the matrix could look like this:

xxxxx
x nxx
xx xx
xnxxx
xxxxx 

And i want to count the numbers of n in the matrix?

Im not good at algorithms so please be gentle with me :)

Was it helpful?

Solution

char[][] M = new char[][];

init(M);
count = 0;

for each row:
  for each element of the row:
    if M[row][column] == specific_char:
      count = count + 1;

return count;

OTHER TIPS

matrix[i][j];//matrix 10x10
j = 0;
i = 0;
for(j = 0 ; j < 9; j++){

  for(i = 0; i < 9 ; i++;){

 if(matrix[j][i]  == character){...}
}

}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top