1 / 5
Sep 2009

Here is my code for the Adding Sevens problem spoj.pl/problems/ANARC08B/

led2Num = {'059' : '0','010' : '1','093' : '2','079' : '3','106' : '4','103' : '5','119' : '6','011' : '7','127' : '8','111' : '9' }
num2Led = {'0' : '059','1' : '010','2' : '093','3' : '079','4' : '106','5' : '103','6' : '119','7' : '011','8' : '127','9' : '111' }
while True:
    data = raw_input()
    if data == 'BYE' :break
    op1, op2 = data[:-1].split('+')
    num1  = ''.join( [ led2Num[ op1[ x : x+3 ] ] for x in range( len( op1 ) )[::3] ] )
    num2  = ''.join( [ led2Num[ op2 [x : x+3 ] ] for x in range( len( op2 ) )[::3] ] )
    answer = ''.join( [ num2Led[ digit ] for digit in str( eval( num1 + '+' + num2 ) ) ] )
    print data+answer

This code runs perfectly fine on my comp in both ways:
1. run the program from console and type the input values by hand
2. put the input values in a file and pipe it to the program
--- Here is the output i get
[ans@ans-lappy Desktop]$ cat ip | python num.py
010+093106=093103
010093+106=010119


but i get the NZEC error after submitting
some one please guide me where i'm going wrong
thanks in advance

  • created

    Sep '09
  • last reply

    Apr '15
  • 4

    replies

  • 483

    views

  • 5

    users

  • 1

    link

I don't know what causes the NZEC, but I can give you hints how to find out:
1. A potential source for the NZEC is a non-existing key in the dicts; if there is only one trailing space in the input, that will happen. You could use

data = raw_input().strip()

to avoid that.
2. Try to localize the error, e.g. by using try-except-clauses or by commenting out single parts. Of course you'll get no AC solution this way, but you can localize the error source more and more and thus you will (probably) find out what causes the NZEC.

The NZEC is for sure due to the fact that your dict is wrong. I simply recommend to check the keys.
For example "111": "9". Is simply not correct.
Create more test cases.

2 months later

Hey dude make a change, u should do:
"059" : 0 as "063" :0
and
"111" :9 as "107":9

thanks.... smile

5 years later

The problem is solvable using Sieve of Eratosthenes, but not the naive one as we are familiar with.Try reading "Art of Programming contest".