s=7 y=[3,5,4,6,8,2,1] y=[8,5,4,6,7,2,1] x=y # 把去掉最大值的y,拆分成2个list maxy=max(y) maxyindex=y.index(maxy) chihuo=[maxy] ly = y[0:maxyindex] ry = y[maxyindex + 1:] print(ly,ry) if ly : while ly: if not ry or not ly: break if ly[-1] > ry[-1]: chihuo.append(ly[-1]) ly=ly[0:-1] else: chihuo.append(ry[-1]) ry=ry[0:-1] if not ry or not ly: lry=ly+ry while lry: if lry[-1] > lry[0]: chihuo.append(lry[-1]) lry = lry[0:-1] else: chihuo.append(lry[0]) lry=lry[1:] print(chihuo) chihuo2=[] chihuo2.append(chihuo[0]) chihuo=chihuo[1:] chanzui=[] for i in range(int(s/2)): chanzui.append(chihuo[i*2]) chihuo2.append(chihuo[i*2+1]) print(chihuo2) print(chanzui) print((sum(chihuo2)))
华为od 馋嘴 吃货
最新推荐文章于 2024-11-04 22:26:34 发布