SRM 707, D2, 250-Pointer (Cross)

James S. Plank

Sat Feb 11 14:26:46 EST 2017
Try this on your own. If you get stuck, return here and read what I've written below.

Given row i and column j, determining whether there is a cross centered at row i and column j is a matter of testing to see whether five characters equal '#'. It's one if statement, which performs the AND of five tests. The main challenge here is to make sure that i and j are not in the first or last row/column. If they are in the first or last row/column, then they cannot center a cross, and your test might segfault (or worse yet, return a wrong answer).

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().