1 / 5
Sep 2016

My solution works on my computer and on ideone.com
But it is giving a NZEC error here on SPOJ. I'm using Python 3.5.2.

t=int(input())
l=[]
c=[]
s=[]
for x in range(t):
    i1=input()
    ll,cc,ss=i1.split(" ")
    l.append(int(ll))
    c.append(int(cc))
    s.append(int(ss))
for x in range(t):
    for y in range(l[x]*(s[x]+1)+1):
        ss=""
        for z in range(c[x]*(s[x]+1)+1):
            rev=c[x]*(s[x]+1)
            sat=y//(s[x]+1)
            sut=z//(s[x]+1)
            if y==0 or y%(s[x]+1)==0 or z==0 or z%(s[x]+1)==0:
                ss=ss+"*"
            elif y%(s[x]+1)==z%(s[x]+1) and (sat+sut)%2==0:
                ss=ss+"\\"
            elif y%(s[x]+1)==(rev-z)%((s[x]+1)) and (sat+sut)%2==1:
                ss=ss+"/"
            else:
                ss=ss+"."
        print(ss)
    print()
  • created

    Sep '16
  • last reply

    Sep '16
  • 4

    replies

  • 910

    views

  • 2

    users

  • 1

    like

here is my another attempt with python2.7 , with the same result :

t=int(raw_input())
l=[]
c=[]
s=[]
for x in range(t):
    i1=raw_input()
    ll,cc,ss=i1.split(" ")
    l.append(int(ll))
    c.append(int(cc))
    s.append(int(ss))
for x in range(t):
    for y in range(l[x]*(s[x]+1)+1):
        ss=""
        for z in range(c[x]*(s[x]+1)+1):
            rev=c[x]*(s[x]+1)
            sat=y//(s[x]+1)
            sut=z//(s[x]+1)
            if y==0 or y%(s[x]+1)==0 or z==0 or z%(s[x]+1)==0:
                ss=ss+"*"
            elif y%(s[x]+1)==z%(s[x]+1) and (sat+sut)%2==0:
                ss=ss+"\\"
            elif y%(s[x]+1)==(rev-z)%((s[x]+1)) and (sat+sut)%2==1:
                ss=ss+"/"
            else:
                ss=ss+"."
        print ss
    if x!=t-1:
        print ''

Try to replace split (" ") by split (). The latter works even if the input contains double spaces or tabs.

it works !! Thank you very much.
Could I know this beforehand? Or, how can SPOJ prevent this happening again for someone else?

Well, all you could have known beforehand is that split() without arguments is more tolerant with respect to whitespace.

That several spoj problems do have mal formatted input is something you learn during problem solving. Often the comments on the problem page give hints.

Unfortunately python is a bit more 'vulnerable' here compated to other common languages, so a lot of users will not even observe any issue.

Most of the spoj problems have worked for me just with the use of split(). Sometimes when handling string input, ".strip() comes in handy, too. And only for very bad input I once used an even more robust approach, posted it here some time ago :wink: