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;
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).