-
Notifications
You must be signed in to change notification settings - Fork 320
/
ch-2.c
31 lines (26 loc) · 1.13 KB
/
ch-2.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# include <stdlib.h>
# include <stdio.h>
# include <string.h>
/*
* See https://theweeklychallenge.org/blog/perl-weekly-challenge-152
*/
/*
* Run as: cc -o ch-2.o ch-2.c; ./ch-2.o < input-file
*/
int min (int a, int b) {return a < b ? a : b;}
int max (int a, int b) {return a < b ? b : a;}
int main (void) {
int a_x1, a_y1, a_x2, a_y2, b_x1, b_y1, b_x2, b_y2;
while (scanf ("%d%d%d%d%d%d%d%d", &a_x1, &a_y1, &a_x2, &a_y2,
&b_x1, &b_y1, &b_x2, &b_y2) == 8) {
printf ("%d\n", (max (a_x1, a_x2) - min (a_x1, a_x2)) *
(max (a_y1, a_y2) - min (a_y1, a_y2)) +
(max (b_x1, b_x2) - min (b_x1, b_x2)) *
(max (b_y1, b_y2) - min (b_y1, b_y2)) -
max (0, min (max (a_x1, a_x2), max (b_x1, b_x2)) -
max (min (a_x1, a_x2), min (b_x1, b_x2))) *
max (0, min (max (a_y1, a_y2), max (b_y1, b_y2)) -
max (min (a_y1, a_y2), min (b_y1, b_y2))));
}
return (0);
}