문제

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 :)

도움이 되었습니까?

해결책

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;

다른 팁

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){...}
}

}
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top