Question

I have a question about CT Scan algorithm In CT scan, multi-dimension scan is executed in order to figure out how many cells

im using c++

0 0
Add a comment Improve this question Transcribed image text
Answer #1

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;
}

Add a comment
Know the answer?
Add Answer to:
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 (...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT