题目
计算矩形覆盖面积
代码语言:javascript复制class Solution {
public:
int computeArea(int A, int B, int C, int D, int E, int F, int G, int H) {
int a =0;
if(E<C&&G>A)
{
if(G>=C&&E>=A)
{
if(H>=D&&F<=B)
{
a = (C-E)*(D-B);
}
else if(H>B&&H<D&&F<=B)
{
a = (C-E)*(H-B);
}
else if(H>=D&&F>B&&F<D)
{
a = (C-E)*(D-F);
}
else if(H<D&&F>B)
{
a = (C-E)*(H-F);
}
}
if(G<C&&E>=A)
{
if(H>=D&&F<=B)
{
a = (G-E)*(D-B);
}
else if(H>B&&H<D&&F<=B)
{
a = (G-E)*(H-B);
}
else if(H>=D&&F>B&&F<D)
{
a = (G-E)*(D-F);
}
else if(H<D&&F>B)
{
a = (G-E)*(H-F);
}
}
if(E<A&&G<C)
{
if(H>=D&&F<=B)
{
a = (G-A)*(D-B);
}
else if(H>B&&H<D&&F<=B)
{
a = (G-A)*(H-B);
}
else if(H>=D&&F>B&&F<D)
{
a = (G-A)*(D-F);
}
else if(H<D&&F>B)
{
a = (G-A)*(H-F);
}
}
if(E<A&&G>=C)
{
if(H>=D&&F<=B)
{
a = (C-A)*(D-B);
}
else if(H>B&&H<D&&F<=B)
{
a = (C-A)*(H-B);
}
else if(H>=D&&F>B&&F<D)
{
a = (C-A)*(D-F);
}
else if(H<D&&F>B)
{
a = (C-A)*(H-F);
}
}
}
return (C-A)*(D-B)-a (G-E)*(H-F);
}
};