CodeChef 上的运行时错误 (NZEC)
Runtime Error(NZEC) on CodeChef
这里是问题:https://www.codechef.com/problems/BUY1GET1
当我提交时,我在 CodeChef 上遇到运行时错误 (NZEC)。
t=int(input())
while(t):
n=input()
#n=list(n)
a=[0]*53
cost=0
for i in n:
if(ord(i)>=65 and ord(i)<=90):
x=ord(i)-64
a[x]=a[x]+1
else:
x=ord(i)-70
a[x]=a[x]+1
#print(a)
for i in range(1,53):
if(a[i]>0):
cost=cost+(a[i]//2+a[i]%2)
print(cost)
t=t-1
它 运行 在我的 Python Shell 上是正确的。
问题是什么?请帮忙!
问题出在 else
块上。
你确定 ord(i)
在 70
和 (70+53-1)
之间吗??
尝试写 elif ord(i) >=70 and ord(i) < 123
而不是 else
并查看问题是否仍然存在。
这里是问题:https://www.codechef.com/problems/BUY1GET1
当我提交时,我在 CodeChef 上遇到运行时错误 (NZEC)。
t=int(input())
while(t):
n=input()
#n=list(n)
a=[0]*53
cost=0
for i in n:
if(ord(i)>=65 and ord(i)<=90):
x=ord(i)-64
a[x]=a[x]+1
else:
x=ord(i)-70
a[x]=a[x]+1
#print(a)
for i in range(1,53):
if(a[i]>0):
cost=cost+(a[i]//2+a[i]%2)
print(cost)
t=t-1
它 运行 在我的 Python Shell 上是正确的。 问题是什么?请帮忙!
问题出在 else
块上。
你确定 ord(i)
在 70
和 (70+53-1)
之间吗??
尝试写 elif ord(i) >=70 and ord(i) < 123
而不是 else
并查看问题是否仍然存在。