a question in a program written in c++

1student

Member
May 30, 2004
42
0
0
Hi, it's me again...
i've a (strange) question - to write a program which gets a 2-dimension array, in the array there are binary values: 0 or 1.
I had to write 2 function:
the first - counts the lit digits - the 1-cells
the second - gets an array and limits. it has to check if there are more than 1 lit digits, if so - it has to reduce the limits, till it gets limits that include just one lit digit - 1, and than prints out it limits.

example:

1) 0 0 0 0
0 1 0 0
0 0 0 0
0 0 0 0

=>> (0,0)(3,3)

2) 1 0 0 1
0 0 1 0
0 0 0 0
1 0 0 0

=>> (0,0)(1,1)
(3,0)(3,0)
(2,1)(2,1)
(0,2)(1,3)

etc..

It's hard to explain... hope u understood.

Here is the progam I wrote:


 

1student

Member
May 30, 2004
42
0
0
Here is what I get:


Enter 4X4 pixels
1 1 0 0
0 1 0 0
1 0 0 1
1 1 1 1
square: (0,0),(0,0)
square: (0,1),(0,1)
square: (1,1),(1,1)
9

instead of getting:
square: (0,0),(0,0)
square: (0,1),(0,1)
square: (1,1),(1,1)
square: (0,2),(0,2)
square: (3,2),(3,2)
square: (0,3),(0,3)
square: (1,3),(1,3)
square: (2,3),(2,3)
square: (3,3),(3,3)
9

Where is the problem?

 

shadowfaX

Senior member
Dec 22, 2000
893
0
0
I haven't really looked into the code much, but seeing that you're doing integer division, it may be that you're "losing" information because you get the floored result, and not a fraction.

Try inserting some couts and in printsBitsSettedOn() to diagnose what's going on.
 

shadowfaX

Senior member
Dec 22, 2000
893
0
0
actually, could you provide another example? i'm a little confused about the ones in your first and second posts.

[ edit ]

never mind, i think i understand what's going on now.

so pretty much, you need the largest square that contains just one lit pixel?
 

1student

Member
May 30, 2004
42
0
0
well,
I have to get all the squares, their size doesn't matter.
What is important here is that in each square will be just one lit pixel - and for each one like this I have to print out the limits (it can be (0,0),(0,0) - if in its area there are some more lit pixels, or (0,0),(3,3) -> in the case that n=4, like what I've written, it says that there is just one lit pixel in the whole square... it can be (0,0),(1,1) etc..)

Its hard to explain.. hope I succeeded...
 

shadowfaX

Senior member
Dec 22, 2000
893
0
0
can i assume that the sides of each square is some power of 2? for instance, 1x1, 2x2, 4x4, 8x8... squares will work, but not 3x3, 5x5, etc?
 

1student

Member
May 30, 2004
42
0
0
somebody?

I'll give u examples so u could see the problem:

1.
Enter 4X4 pixels
0 1 0 0
0 1 0 0
0 0 0 0
0 0 0 0
square: (0,1),(0,1)
square: (1,1),(1,1)
2
2.
Enter 4X4 pixels
0 1 0 0
1 0 0 0
0 0 0 0
0 0 0 0
square: (0,1),(0,1)
2
Pay attention to the location of the 2nd lit pixel in each one of the ex. above...

 
sale-70-410-exam    | Exam-200-125-pdf    | we-sale-70-410-exam    | hot-sale-70-410-exam    | Latest-exam-700-603-Dumps    | Dumps-98-363-exams-date    | Certs-200-125-date    | Dumps-300-075-exams-date    | hot-sale-book-C8010-726-book    | Hot-Sale-200-310-Exam    | Exam-Description-200-310-dumps?    | hot-sale-book-200-125-book    | Latest-Updated-300-209-Exam    | Dumps-210-260-exams-date    | Download-200-125-Exam-PDF    | Exam-Description-300-101-dumps    | Certs-300-101-date    | Hot-Sale-300-075-Exam    | Latest-exam-200-125-Dumps    | Exam-Description-200-125-dumps    | Latest-Updated-300-075-Exam    | hot-sale-book-210-260-book    | Dumps-200-901-exams-date    | Certs-200-901-date    | Latest-exam-1Z0-062-Dumps    | Hot-Sale-1Z0-062-Exam    | Certs-CSSLP-date    | 100%-Pass-70-383-Exams    | Latest-JN0-360-real-exam-questions    | 100%-Pass-4A0-100-Real-Exam-Questions    | Dumps-300-135-exams-date    | Passed-200-105-Tech-Exams    | Latest-Updated-200-310-Exam    | Download-300-070-Exam-PDF    | Hot-Sale-JN0-360-Exam    | 100%-Pass-JN0-360-Exams    | 100%-Pass-JN0-360-Real-Exam-Questions    | Dumps-JN0-360-exams-date    | Exam-Description-1Z0-876-dumps    | Latest-exam-1Z0-876-Dumps    | Dumps-HPE0-Y53-exams-date    | 2017-Latest-HPE0-Y53-Exam    | 100%-Pass-HPE0-Y53-Real-Exam-Questions    | Pass-4A0-100-Exam    | Latest-4A0-100-Questions    | Dumps-98-365-exams-date    | 2017-Latest-98-365-Exam    | 100%-Pass-VCS-254-Exams    | 2017-Latest-VCS-273-Exam    | Dumps-200-355-exams-date    | 2017-Latest-300-320-Exam    | Pass-300-101-Exam    | 100%-Pass-300-115-Exams    |
http://www.portvapes.co.uk/    | http://www.portvapes.co.uk/    |