码迷,mamicode.com
首页 > 编程语言 > 详细

Python 实现两个矩形重合面积

时间:2019-08-29 00:17:13      阅读:368      评论:0      收藏:0      [点我收藏+]

标签:nbsp   class   lse   size   print   port   imp   pytho   code   

计算两个矩形的重合面积
import math
x1, y1, x2, y2 = input().split(" ")
x1, y1, x2, y2=int(x1), int(y1), int(x2), int(y2)
# print(x1, y1, x2, y2)
x1,x2 = min(x1,x2),max(x1,x2)
y1,y2= min(y1,y2),max(y1,y2)

# print(x1, y1, x2, y2)

x3, y3, x4, y4 = input().split(" ")
x3, y3, x4, y4 = int(x3), int(y3), int(x4), int(y4)
x3,x4 = min(x3,x4),max(x3,x4)
y3,y4 = min(y3,y4),max(y3,y4)

# print(x3, y3, x4, y4)

if (x2<=x3 or x4<=x1) and (y2 <= y3 or y4<=y1):
    print(0)
else:
    lens = min(x2, x4) - max(x1, x3)
    wide = min(y2, y4) - max(y1, y3)
    print(lens*wide)

 

Python 实现两个矩形重合面积

标签:nbsp   class   lse   size   print   port   imp   pytho   code   

原文地址:https://www.cnblogs.com/chenpython123/p/11427275.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!