Element ( i-1, j ) = '#' Element ( i, j-1 ) = '#' Element ( i, j ) = '#' Element ( i, j+1 ) = '#' Element ( i+1, j ) = '#'
Example | Input | Answer |
0 | {".##", "###", "##."} |
"Exist" |
1 | {".##", "###", "#.."} |
"Does not exist" |
2 | {"######", "######", "######", "######", "######", "######", "######"} |
"Exist" |
3 | {".#.#", "#.#.", ".#.#", "#.#."} |
"Does not exist" |
4 | {".#.#", "###.", ".###", "#.#."} |
"Exist" |
So, what I did was have nested for loops, one for rows (i) and one for columns(j). Each loop starts at one instead of zero, and the termination test for i is to make sure that it is less than board.size()-1 rather than board.size(), like you usually do with a loop. The termination test for j is similar, making sure it is less than board[0].size()-1 rather than board[0].size().