First, since the input is line oriented, I'd use std::getline
for each line. The traditional approach after that would be to
use std::istringstream
to parse the values in the line, but
for something this simple (where each digit has a fixed
location, and the actual values are only a single digit), it's
probably just as simple to extract the values directly from the
string: character - '0'
for the respective character. (Output
is similar: cellValue + '0', inserting additional spaces where
necessary.)
I'd also forgo the Cell
class, and simply use an
std::vector<int> grid(81);
for the entire grid. It's probably
easier to keep all of the relevant information in a Grid
class. This depends, and both solutions are viable. But
I certainly wouldn't keep row
, column
and block
in
Cell
, since they aren't characteristics of the cell, but
rather of where it is placed in the grid. And I wouldn't keep
candidateList
in the cell either: at any given moment, the
cell has only one value, and the candidate list is only
relevant for the cell(s) you're currently looking at, and is
best implemented as a local variable.