Reputation: 23
Here is the Question: https://www.codechef.com/problems/BUY1GET1
When I submit I am getting a Runtime Error(NZEC) on CodeChef.
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
Its running correctly on my Python Shell. What is the problem? Please Help!
Upvotes: 0
Views: 158
Reputation: 8576
The problem is with the else
block.
Are you absolutely sure that ord(i)
is between 70
and (70+53-1)
??
Try writing elif ord(i) >=70 and ord(i) < 123
instead of else
and see if the problem persists.
Upvotes: 0