mainl() {int bestw = 32767, i, j,k, besti, bestj, bestk; float w,a[10]; for (i=1;i<=9;i=i+1) input(a[i]); for (i=1;i<=7;i=i+1) for(j=i+1;j<=8;j=j+1) for(k=j+1;k<=9;k=k+1) {w=ABS(500-a[i]-a[j]-a[k]); if(w<bestw) {bestw =w; besti=i; bestj=j; bestk = k;} print("choose: ",besti,bestj,bestk); print ("weight: ",a[ besti] + a[bestj] + a[bestk]);转换成python语言的代码
时间: 2024-03-30 16:38:07 浏览: 45
mainL1DISC
bestw = 32767
a = [0]*10
for i in range(1, 10):
a[i] = float(input())
for i in range(1, 7):
for j in range(i+1, 8):
for k in range(j+1, 9):
w = abs(500 - a[i] - a[j] - a[k])
if w < bestw:
bestw = w
besti = i
bestj = j
bestk = k
print("choose: ", besti, bestj, bestk)
print("weight: ", a[besti] + a[bestj] + a[bestk])
阅读全文