To simply find out the number of cells filled with B.
You can add the contents of second row and third row.
In this case 1st row (1 + 3 + 2 + 2) and 2nd Row(1 + 4 + 2 + 1).
In both the cases the sum is 8 which is equal to the number of B's present in the matrix.
Therefore the verification condition will be sum of first row == sum of second row.
Code:
int getCellsCount(string fileName)
{
ifstream fin;
fin.open(fileName);
if (!fin.is_open())
return {};
string firstline;
getline(fin, firstline);
string line;
int lineno = 1;
int sumRow = 0, sumColumn = 0;
while (getline(fin, line))
{
stringstream ss(line);
int num;
while (ss >> num)
{
if (lineno ==
1)
sumRow += num;
else if(lineno
== 2)
sumColumn += num;
}
if (lineno == 2)
break;
lineno++;
}
if (sumRow == sumColumn)
return sumRow;
}
im using c++ I have a question about CT Scan algorithm In CT scan, multi-dimension scan is executed in order to figure out how many cells are filled with B's In input files, the first line N (...