I can’t find anything really wrong with my solution, yet it fails testcase 6. Also, is there a “smarter” method than if/else casework?
/*
http://www.usaco.org/index.php?page=viewproblem2&cpid=783
c1: 4 corners
c2: 0 corners
c3: 2 corners
c4: 1 corner
*/
#include <iostream>
#include <cmath>
using namespace std;
int main()
{
freopen("billboard.in", "r", stdin);
freopen("billboard.out", "w", stdout);
int lx1,ly1,lx2,ly2; cin>>lx1>>ly1>>lx2>>ly2; //lawnmower
int fx1,fy1,fx2,fy2; cin>>fx1>>fy1>>fx2>>fy2; //feed
if(fx1<=lx1&&fx2>=lx2&&fy1<=ly1&&fy2>=ly2){ // 4 corners
cout<<0;
}
else if(fy2<ly1||fx2<lx1||fy1>ly2||fx1>lx2||(ly1<fy1&&ly2>fy2)||(lx1<fx1&&lx2>fx2)){ // 0 corners
cout<<(lx2-lx1)*(ly2-ly1);
}
else if(fx1<lx1&&lx1<lx2&&lx2<fx2){ // 2 corners, x
cout<<(lx2-lx1)*abs(fy1-ly1);
}
else if (fy1<ly1&&ly1<ly2&&ly2<fy2){ // 2 corners, y
cout<<(ly2-ly1)*(fx2-fx1);
}
// else if((fx1<lx1&&)||()||()||()){ // 1 corner
else{
cout<<(lx2-lx1)*(ly2-ly1);
}
cout<<"\n";
return 0;
}