题目:

 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)

 

相关文章:

  • 2021-11-24
  • 2022-12-23
  • 2022-03-04
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-02-25
  • 2021-12-01
猜你喜欢
  • 2021-06-08
  • 2022-12-23
  • 2021-08-04
  • 2023-03-14
  • 2021-06-14
  • 2021-08-04
  • 2022-12-23
相关资源
相似解决方案