2013-03-22 86 views
3

的问题是this: 我试图解决这个问题,我想我确实做了,但是当我寄出了评价它说运行时错误退出,错误状态1

We have tested your solution, and while doing so we unfortunately 
discovered the following error: 
Run Time Error 

Exited with error status 1 

这里是我的代码:

import re 
import sys 
def fun(): 
    for ind in ratio: 
     max_num = ratio_list[0] 
     if ratio[ind] == max_num: 
      print ind 

    ratio_list.remove(ratio_list[0]) 

hits = [] 
song = [] 
n,m = raw_input().split(' ',1) 


for i in range(0,int(n)): 
    h,n = raw_input().split(" ",1) 

    is_number = isinstance(int(h), int) 
    is_string = len(n)<=30 and bool(re.match('[a-z_0-9]+$', n)) 
    if not(is_number and is_string): 
     sys.exit("Error"); 
    hits.append(int(h)) 
    song.append(n) 
ratio = {} 
ratio_list = [] 
f_of_i = hits[0] 
counter = 1 
index = 0 

for hit in hits: 
    ratio_list.append(hit*counter) 
    ratio[song[index]] = hit*counter 
    index = index +1 
    counter = counter +1 

ratio_list.sort() 
ratio_list.reverse() 

for j in range(0,int(m)): 
    fun() 

我在做什么错?我很好奇为什么这个解决方案不能令我接受。

+0

我不认为自动化解决方案测试会提供'raw_input()'输入。他们更倾向于给程序一个输入文件。你的程序应该解析它,然后打印输出。 – 2013-03-22 11:21:50

+0

我看到的一件事是,您不会将'fun()'函数的'ratio'作为参数。这不是一本全球性的字典。当然,这可能不会解决您的运行时错误。 – 2013-03-22 11:22:00

+0

@Allendar它没有错误。有用。 – Leonidus 2013-03-22 11:22:41

回答

4

我怀疑你打

sys.exit("Error"); 

正如documentation解释说:

一些系统具有特定退出代码指定特定的含义惯例,不过一般都是不发达; Unix程序通常使用2作为命令行语法错误,1使用其他类型的错误。如果对象的另一种类型的通过,没有相当于传递零,和任何其他对象被打印到stderr,并且导致的1

退出代码可能是值得放松你输入验证一点?现在它非常严格,它会拒绝我在规范中出现的输入(例如,如果播放计数和歌曲标题之间有两个空格)。

另一种可能性是您的代码引发异常。在我的机器上,这也导致退出代码为1.

最后,虽然没有错误,但我认为您重复使用名为n的变量的方式是值得怀疑的风格。

+0

让我试试看。 :D,但是如果歌曲名称包含“a-z0-9”以外的任何内容,我需要提供一个终止规则,你如何建议我这么做? – Leonidus 2013-03-22 11:38:55

+0

可能版本是一个问题?导致我的机器运行良好。 :/ – Leonidus 2013-03-22 11:42:54

+0

@Leonidus:是的,版本可能是一个问题。我的建议是使用他们使用的相同版本的Python(2.6)。 – NPE 2013-03-22 11:43:36

相关问题