When presented with such a problem, it helps to break it down into smaller sub-problems first to solve individually, before composing together into the solution. While it's technically quite possible to write it as one function, it can help in understanding the issue and implementation and ultimately yield cleaner code.
We know that we have to write a program that:
- Reads the data for two rectangles,
- Computes the common area,
- Prints it out.
Reading the data is actually often more complex than writing it in programming. This is because the data is often coming in a different format than what we need it for our purposes. In this case, the rectangle data is gonna arrive as characters on standard input (presumably separated by whitespace), and those characters will encode the x,y, w and h of two rectangles. For our purposes, it's best to have them stored as numbers in memory, so we need to parse the input, converting into our format.