Odpowiedź:
#include <iostream>
#include <cstdlib>
#include <algorithm>
using namespace std;
int main() {
int x1[2], x2[2], y1[2], y2[2], x[4], y[4], a, b;
cin >> x1[0] >> y1[0] >> x1[1] >> y1[1];
cin >> x2[0] >> y2[0] >> x2[1] >> y2[1];
x[0] = min(x1[0], x1[1]);
x[1] = max(x1[0], x1[1]);
x[2] = min(x2[0], x2[1]);
x[3] = max(x2[0], x2[1]);
if (x[2] >= x[0] && x[2] < x[1] && x[3] >= x[1]) a = x[1] - x[2];
else if (x[3] <= x[1] && x[3] > x[0] && x[2] <= x[0]) a = x[3] - x[0];
else if (x[2] > x[0] && x[3] < x[1]) a = x[3] - x[2];
else a = x[1] - x[0];
y[0] = min(y1[0], y1[1]);
y[1] = max(y1[0], y1[1]);
y[2] = min(y2[0], y2[1]);
y[3] = max(y2[0], y2[1]);
if (y[2] >= y[0] && y[2] < y[1] && y[3] >= y[1]) b = y[1] - y[2];
else if (y[3] <= y[1] && y[3] > y[0] && y[2] <= y[0]) b = y[3] - y[0];
else if (y[2] > y[0] && y[3] < y[1]) b = y[3] - y[2];
else b = y[1] - y[0];
cout << a*b;
getchar();
return 0;
}
Wyjaśnienie: