题目:
1 第一列为商品成本价格 2 第二列为商品卖出价格 3 第三列为本金 4 要求: 5 1.每种商品只能买入卖出一次 6 2.求最大收益 7 8 例子: 9 输入:10 3,1,5,4,311 4,7,6,6,412 1613 14 输出:15 2716 (先买入前四种,然后卖出,再买入第五种)
代码:
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 = price16 #一个一个取值,如果成本价大余额,则跳出17 for i in range(len(cost)):18 if sur > cost[i]:19 surNew = sur - cost[i] + profit[i]20 sur = surNew21 else:22 break23 endPrice = price + sur24 print(endPrice)
总结
以上是内存溢出为你收集整理的python 练习题- 最大收益全部内容,希望文章能够帮你解决python 练习题- 最大收益所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)