Reputation: 28
Given below is my code in Python3 for a Codechef challenge:
from itertools import groupby
counter=int(input())
arg=[]
p=[]
for i in range(int(counter)):
arg.append(input())
num=0
while (num<counter):
x=arg[num]
l=x.replace('=','')
groups=groupby(y)
result = [(label, sum(1 for _ in group)) for label, group in groups]
for i in range(0,len(result)):
p.append(result[i][1])
print (max(p)+1)
p=[]
num+=1
I am encountering a Runtime Error(NZEC) for four of the eight test cases. I already checked on the https://discuss.codechef.com/questions/7593/why-do-i-get-an-nzec,but could not find the solution to this problem.Any help would be great.Thanks in advance.
EDIT1: I fixed the Traceback and it is still giving NZEC in two out of four cases.The code is:
from itertools import groupby
counter=int(input())
arg=[]
p=[]
for i in range(int(counter)):
arg.append(input())
num=0
while (num<counter):
x=arg[num]
l=x.replace('=','')
groups=groupby(l)
result = [(label, sum(1 for _ in group)) for label, group in groups]
for i in range(0,len(result)):
p.append(result[i][1])
print (max(p)+1)
p=[]
num+=1
The question says that the first line contains the number of test cases.Each of the following line contains each test case which I am taking as input one by one,as mentioned in the question.Still it is giving the same error.The problem is I frequently encounter NZEC error while using Python as the language in Codechef.
Upvotes: 0
Views: 305
Reputation:
PUT ALL CODE IN TRY EXCEPT BCZ CODECHEF USE FILE AS AN INPUT I DID IN MY CODE AND IT'S WORKS
from itertools import groupby
try:
counter=int(input())
arg=[]
p=[]
for i in range(int(counter)):
arg.append(input())
num=0
while (num<counter):
x=arg[num]
l=x.replace('=','')
groups=groupby(y)
result = [(label, sum(1 for _ in group)) for label, group in groups]
for i in range(0,len(result)):
p.append(result[i][1])
print (max(p)+1)
p=[]
num+=1
except:
pass
Upvotes: 0