2017-05-06 5 views
0

Topcoder problem에서 코드를 실행하면 IndexError : 목록 색인이 범위를 벗어났습니다. 그러나 코드는 Python IDLE에서 완벽하게 작동했습니다. 누가 잘못했는지 말해 줄 수 있니? 당신의 data 때문에 탑 코더에서 제공하는 테스트 입력에 예기치 않은 EOF에 비어 있기 때문에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 
+0

이 코드가 어떻게 유휴 상태에서 완벽하게 작동하는지 알 수 없습니다. split() 함수는 하나의 항목으로 목록을 반환합니다. –

+0

이 문제에 대한 유효성 검사 테스트에 몇 가지 문제가있을 수 있습니다. –

+0

예를 들어, 입력은 '5 5 5 2'이고 split() 함수는 [ '5', '5', '5', '2']를 반환합니다. –

답변

0

당신은 인덱스 오류가 있습니다. 입력간에 EOF 예외를 처리하기 위해 코드를 구현해 볼 수 있습니다.

+0

'코드 구현'이란 무엇입니까? –

+0

입력을 가져 오는 동안 예외 처리를 구현할 수 있습니다. – Tarptaeya