Advertisement
TransactCharlie

Problem A. Speaking in Tongues

Apr 15th, 2012
116
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.36 KB | None | 0 0
  1. __author__ = 'charles'
  2.  
  3. inputFile = "a-small-attempt0.in"
  4. outputFile = inputFile + ".out"
  5.  
  6. translated = 'ejp mysljylc kd kxveddknmc re jsicpdrysirbcpc ypc rtcsra dkh wyfrepkym veddknkmkrkcdde kr kd eoya kw aej tysr re ujdr lkgc jvy qeez'
  7. orriginal =  'our language is impossible to understandthere are twenty six factorial possibilitiesso it is okay if you want to just give upa zooq'
  8.  
  9. trans = {}
  10.  
  11. for i,v in enumerate(translated):
  12.     trans[v] = orriginal[i]
  13.  
  14. class Translate(object):
  15.  
  16.     def __init__(self, text):
  17.         self.text = text
  18.  
  19.     def DisplayCase(self):
  20.         print "Case : " + ",".join(self.text)
  21.  
  22.     def SolveCase(self):
  23.         reverse = ""
  24.         for c in self.text:
  25.             reverse += trans[c]
  26.  
  27.         return reverse
  28.  
  29. def extractTestCases(filename):
  30.  
  31.     with open(filename, 'r') as f:
  32.         fileContents = (f.read().splitlines())
  33.         f.close()
  34.  
  35.     cases = []
  36.     for c in range(0,int(fileContents[0])):
  37.         cases.append(Translate(fileContents[c+1]))
  38.  
  39.     return cases
  40.  
  41. def main():
  42.     cases = extractTestCases(inputFile)
  43.  
  44.  
  45.     for case in cases:
  46.         print case.DisplayCase()
  47.  
  48.  
  49.     with open(outputFile, "w") as w:
  50.         for n in range(0, len(cases)):
  51.             case = cases[n]
  52.             w.write("Case #" + str(n + 1) + ": " + case.SolveCase() + "\n")
  53.  
  54. if __name__ == "__main__":
  55.     main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement