NZEC - python 中的运行时错误 [英] NZEC - Runtime Error in python
问题描述
我说最近在练习 CodeChef,我提交的每个程序都会出现 NZEC 运行时错误.即使是一个简单的程序将两个数字相加 n 次,例如:
I stated practicing CodeChef recently and every program I submit gives me NZEC runtime error. Even a simple program to add two numbers n number of time like:
for _ in xrange(input()):
print input()+input()
以及打印银行余额的程序
and a program to for printing bank balance
withdraw = input()
balance = input()
if withdraw % 5 == 0 and (balance - withdraw - 0.5)>0:
f = balance - withdraw - 0.5
print "%0.2f" %f
else:
print "%0.2f" %balance
给出相同的错误.谁能帮我这个?提前致谢.
gives the same error. Can anyone help me with this? Thank you in advance.
PS:我正在使用 python IDLE 和 PyCharm.两者都给出了适当的输出.我在 CodeChef 和 www.ideone.com 中出错
PS: I'm using python IDLE and PyCharm. Both gave proper outputs. I got error in CodeChef and www.ideone.com
推荐答案
好吧,也许没有人看到这个帖子或者没有人试图回答这个问题,我尝试了很多并找到了答案.我正在为那些可能与我遇到同样问题的人回答我自己的问题.当我们在线提交代码时,他们以文本文件的形式提供输入.因此,输入在一行中.
Well, maybe nobody saw this post or nobody has tried to answer this, I tried a lot and found the answer for this. I'm answering my own question for those who might have the same problem I had. When we submit codes online, they give the input as a text file. Hence the inputs are in a single line.
我尝试了我在 Hackerrank 的问题中提交的相同程序,并提供了来自 CodeChef's 站点,发现错误是输入在同一行上.我将代码更改为:
I tried the same program I submitted in the question in Hackerrank and gave the custom inputs from CodeChef's site and found that the error was that the inputs were on the same line. I changed my code to:
t = input()
while(t):
num = raw_input().split()
n = int(num[0])
k = int(num[1])
a = raw_input().split()
a = [float(a[x]) for x in xrange(n)]
if(n>2*k):
while(k):
a.remove(max(a))
a.remove(min(a))
k-=1
print '%.06f' %(sum(a)/len(a))
t-=1
现在工作正常但没有得到满分.我希望一些可能面临同样问题的新手发现这很有用.
Works fine now didn't get full marks though. I hope some newbie who might face the same problem I did finds this useful.
这篇关于NZEC - python 中的运行时错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!