I was very intrigued with the manner to solve this problem. The program needs to know if 2 rectangles fit in another one, considering the lines of the 2 rectangles are always parallel to the other one's. I know I could just put everything in a single if, but is that more readable? I want to know a good approach for this situation, using only conditions.
NOTE: x and y represent the first rectangle's width and height (the one that will fit the other 2) and l1, h1, l2, and h2 represent the other 2 rectangles' width and height.
#include <stdio.h>
int main(void)
{
int x, y, l1, h1, l2, h2;
scanf("%d %d %d %d %d %d", &x, &y, &l1, &h1, &l2, &h2);
if ((l1 + l2 <= x && h1 <= y && h2 <= y) ||
(h1 + h2 <= x && l1 <= y && l2 <= y))
{
puts("They fit.");
}
else if ((l1 <= x && h2 <= x && h1 + l2 <= y) ||
(h1 <= x && l2 <= x && l1 + h2 <= y))
{
puts("They fit.");
}
else if ((l1 <= y && h2 <= y && h1 + l2 <= x) ||
(h1 <= y && l2 <= y && l1 + h2 <= x))
{
puts("They fit.");
}
else if ((l1 + l2 <= y && h1 <= x && h2 <= x) ||
(h1 + h2 <= y && l1 <= x && l2 <= x))
{
puts("They fit.");
}
else
{
puts("They don't fit.");
}
return 0;
}