• We’re currently investigating an issue related to the forum theme and styling that is impacting page layout and visual formatting. The problem has been identified, and we are actively working on a resolution. There is no impact to user data or functionality, this is strictly a front-end display issue. We’ll post an update once the fix has been deployed. Thanks for your patience while we get this sorted.

a question in a program written in c++

1student

Member
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:


 
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?

 
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.
 
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?
 
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...
 
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?
 
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...

 
Back
Top