Problems with array.

In the following programme, i was trying to use a graphic method to find the
overlap area of n rectangles. x, is the x coordinate of the left bottom, so does y. When i input 2 2 3 3 3 2 2 2 2, the output was
23
24
25
26
27
28
29
30
31
22
23
24
25

in which 23 means (2,3). However, im stuck at how i can compare and increase the counter if the number is repeated, i.e. 23, 24 and 25. i want the counter to be 3. HOW CAN I DO THAT???? PLEASEEEEE HELPPPPP


#include <iostream>
using namespace std;

int main() {
int area[10000];
int n, x, y, width, height, counter=0;
cin >> n;
for (int a=0; a<n; a++){
cin >> x >> y >> width >> height;
for (int i=0; i< width*height; i++, y++){
area[i] = (x*10) + y;
cout << area[i] << endl;

}
}

return 0;
}
Don't use a graphical method.

If you overlap two rectangles then the overlap will be a rectangle extending in the x direction from the greater of the two left x values to the lesser of the two right x values, and similarly in the y direction. (If there is no overlap the bounds will be in the wrong order and your area becomes 0).

Easily extended to more rectangles.

Your question could have been a lot clearer, BTW.
Last edited on
Topic archived. No new replies allowed.