IndexError:列表索引超出Topcoder提交范围
当我在Topcoder problem中运行我的代码时,它显示出现以下错误:IndexError:列表索引超出范围。但是,代码在Python IDLE上完美工作。谁能告诉我哪里错了?IndexError:列表索引超出Topcoder提交范围
Problem Info:
Definition Class:
CheeseSlicing Method: totalArea
Parameters: integer, integer, integer, integer
Returns: integer Method
signature: def totalArea(self, A, B, C, S):
Examples
0) 1 3 3 2
Returns: 0
One of the dimensions of this block is 1. Regardless of how we cut it, each piece will have one dimension equal to 1. As S=2, this means that producing a good slice is impossible. Hence, the maximum total surface area of good slices is 0.
import sys
total=0
data=sys.stdin.read().split()
x,y,z,s=int(data[0]),int(data[1]),int(data[2]),int(data[3])
if min(x,y,z)==s:
print x*y*z/s
elif min(x,y,z)<s:
print 0
elif max(x,y,z)>s:
lines=[x,y,z]
while max(lines)>=2*s:
area=1
maxline=max(lines)
lines.pop(lines.index(maxline))
for line in lines:
area=area*line
total+=area
lines.append(maxline-s)
area=1
minline=min(lines)
lines.pop(lines.index(minline))
for line in lines:
area=area*line
total+=area
print total
你得到指数错误,因为你的data
是空的,由于在由TopCoder公司提供的测试输入意外EOF。你可以尝试实现你的代码来处理输入之间的EOF异常。
你是什么意思'实现你的代码'? –
您可以在输入时实现异常处理 – Tarptaeya
我不知道,这个代码如何在你的IDLE中完美工作。 split()函数将返回带有一个项目的列表。 –
Topcoder有可能在此问题的验证测试中遇到一些问题。 –
例如,输入将是'5 5 5 2',split()函数将返回['5','5','5','2']。 –