Python计算两个矩形重合面积代码实例
作者:chentao2018 时间:2021-12-18 23:34:22
这篇文章主要介绍了Python 实现两个矩形重合面积代码实例,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友可以参考下
代码如下
计算两个矩形的重合面积
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)
字符串重叠输出
import string
in_str = input()
nums = string.digits
a = ""
strs = ""
num = ""
for i in range(len(in_str)):
if in_str[i] not in nums:
a = a+in_str[i]
else:
if i == len(in_str)-1 or (in_str[i+1] not in nums):
num = int(num + in_str[i])
strs = strs + a*num
a=""
num=""
else:
num = num + in_str[i]
print(strs)
来源:https://www.cnblogs.com/chenpython123/p/11427275.html
标签:python,矩形,重合,面积
![](/images/zang.png)
![](/images/jiucuo.png)
猜你喜欢
django 在原有表格添加或删除字段的实例
2023-11-25 04:21:08
Python爬取豆瓣视频信息代码实例
2021-10-28 06:41:46
![](https://img.aspxhome.com/file/2023/3/84993_0s.jpg)
javascript基础之数组(Array)对象
2008-06-25 13:32:00
ASP:判断访问是否来自搜索引擎的函数
2008-03-12 11:39:00
Python实现FLV视频拼接功能
2021-09-19 02:41:48
谈中国站长站的文章干扰码实现方法
2007-10-13 11:13:00
![](https://img.aspxhome.com/file/UploadPic/up/2007101313560193.jpg)
php 伪造本地文件包含漏洞的代码
2023-11-17 06:36:40
MySQL数据库中CHAR与VARCHAR之争
2011-05-05 16:33:00
精简版的MySQL制作步骤
2011-03-08 09:52:00
ORACLE数据库应用开发常见问题及排除
2010-07-26 13:17:00
Python seaborn barplot画图案例
2023-11-07 00:50:55
![](https://img.aspxhome.com/file/2023/7/63977_0s.png)
ASP UTF-8编码下字符串截取和获取长度函数
2011-03-30 10:52:00
Python批量修改文件名的方式详解
2023-05-15 20:56:08
![](https://img.aspxhome.com/file/2023/3/115683_0s.jpg)
python实现百度文库自动化爬取
2023-02-01 23:57:22
python3 读取Excel表格中的数据
2021-01-14 23:03:42
如何正确合理的建立MYSQL数据库索引
2010-10-25 20:08:00
SQLServer 2000 升级到 SQLServer 2008 性能之需要注意的地方之一
2012-02-25 19:44:26
Numpy之将矩阵拉成向量的实例
2023-10-13 10:44:01
python实现DNS正向查询、反向查询的例子
2022-10-29 07:18:55
Python实现二叉堆
2023-12-24 13:40:48
![](https://img.aspxhome.com/file/2023/6/133796_0s.png)