NZEC Error

Solution 1: click here

Solution 2 : click here

What is the difference between this two programs.

I just replaced for loop in place of while loop while reading test cases. After this change judge accepted my answer. Before it gave me NZEC Error.

Please Help me with this as i got this error in many problems.

1 Like

In the while version, you haven’t decremented t in the case of no score. The continue restarts the next pass of the loop without executing that. That means that you lose track of the number of test cases performed and try to pull output after the last test case, which gives you your error.

Arguably you could decrement t immediately (at the top of the while loop), but the for statement in this case seems better.

For a more “Pythonic” answer to this challenge:

for _ in range(int(input())):
    vs = input().strip()

    ctA = sum(len(Ai.strip('.')) for Ai in vs.split('B'))

    ctB = sum(len(Bi.strip('.')) for Bi in vs.split('A'))

    print(ctA, ctB)

Note, this is not a “correction” - your general approach is good - it’s just intended for interest, with an element of challenge to figure out how it works :slight_smile: .

Well done for giving links and and explanation with your request for help.