0
点赞
收藏
分享

微信扫一扫

python 练习题- 最大收益

静鸡鸡的JC 2022-08-11 阅读 68

题目:

1 第一列为商品成本价格
2 第二列为商品卖出价格
3 第三列为本金
4 要求:
5 1.每种商品只能买入卖出一次
6 2.求最大收益
7
8 例子:
9 输入:
10 3,1,5,4,3
11 4,7,6,6,4
12 16
13
14 输出:
15 27
16

 

代码:

1 # @Author  :whyCai
2 # @Time :2021/2/23 22:00
3
4 import sys
5 if __name__ == "__main__":
6 # 取值
7 cost = sys.stdin.readline().strip()
8 sell = sys.stdin.readline().strip()
9 price = int(sys.stdin.readline().strip())
10 cost = list(map(int, cost.split(',')))
11 sell = list(map(int, sell.split(',')))
12
13 #取成本和卖出价格差
14 profit = list(map(lambda x: x[1]-x[0], zip(cost, sell)))
15 sur = price
16 #一个一个取值,如果成本价大余额,则跳出
17 for i in range(len(cost)):
18 if sur > cost[i]:
19 surNew = sur - cost[i] + profit[i]
20 sur = surNew
21 else:
22 break
23 endPrice = price + sur
24 print(endPrice)

 



举报

相关推荐

python 练习题

python练习题

Python练习题

python 练习题-质数

Python列表练习题

【Python】函数练习题

python练习题(一)

0 条评论