Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 Dwight Round 5 Question 4
Index -> CompSci.ca, Contests -> DWITE
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
EdTsft




PostPosted: Thu Mar 25, 2010 1:32 pm   Post subject: Dwight Round 5 Question 4

Hi,
On question 4 of round 5 I was having some trouble with the judge and I was wondering if anyone could tell me why this was happening.

My solution (http://dwite.org/uploads/dafrerU274/1235/107/0/5prob4.py) runs fine using python 2.5.1 on the computer I am using and correctly solves the test data now that it is up. However, when I had submitted it to the judge it got zero points with an error of:
(as far a I can remember of significance)

Program returned with code 1
Found output file
Tests ran OK
Not enough lines in output file.
Score of 0

When I run the program it outputs the correct solution with the correct number of lines. If someone knows why that happened I'd like to know so the same thing dosen't happen again or to bring it to attention if it's a bug.

He is my program, written in python.

code:

letters = {("x.","xx"):"A",("xx","xx"):"B",("x.x","xxx"):"C",("xx",".x"):"D",("xxx",".xx"):"E"}
   
fin = open("DATA4.txt","r")
fout = open("OUT4.txt","w")

def parse(top,bottom,buff=""):
    if top=="":
        return buff
    if len(top)==1:
        return -1
    if (top[0:2],bottom[0:2]) in letters:
        ret = parse(top[2:],bottom[2:],buff+letters[(top[0:2],bottom[0:2])])
        if ret != -1:
            return ret
    if (top[0:3],bottom[0:3]) in letters:
        ret = parse(top[3:],bottom[3:],buff+letters[(top[0:3],bottom[0:3])])
        if ret != -1:
            return ret
    return -1

for i in range(5):
    top = fin.readline().strip("\n ")
    bottom = fin.readline().strip("\n ")
    if i != 4:
        fout.write(str(parse(top,bottom))+"\n") #to keep the program working even if an invalid string is passed
    else:
        fout.write(parse(top,bottom))
fin.close()
fout.close()
Sponsor
Sponsor
Sponsor
sponsor
Display posts from previous:   
   Index -> CompSci.ca, Contests -> DWITE
View previous topic Tell A FriendPrintable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 1  [ 1 Posts ]
Jump to:   


Style:  
Search: