fork(1) download
  1. def parse(inFile):
  2. words = inFile.getWords()
  3. C = int(words[0])
  4. combinations = words[1:(C+1)]
  5. D = int(words[C+1])
  6. oppositions = words[C+2:(C+D+2)]
  7. return (combinations, oppositions, words[C+D+3])
  8.  
  9. def solve((combinations, oppositions, word)):
  10. cs = {}
  11. for combo in combinations:
  12. cs[combo[:2]] = combo[2]
  13. cs[combo[1]+combo[0]] = combo[2]
  14. os = set([])
  15. for oppo in oppositions:
  16. os.add(oppo)
  17. os.add(oppo[::-1])
  18. data = []
  19. for letter in word:
  20. if len(data) == 0:
  21. data = [letter]
  22. else:
  23. if (data[-1] + letter) in cs:
  24. data += [letter]
  25. while (len(data) > 1 and data[-2]+data[-1] in cs):
  26. data = data[:-2] + [cs[data[-2]+data[-1]]]
  27. elif len([1 for datum in data if (datum + letter) in os]):
  28. data = []
  29. else:
  30. data.append(letter)
  31. return str(data).replace("'","")
  32.  
  33. if __name__ == "__main__":
  34. from GCJ import GCJ
  35. GCJ(parse, solve, "/Users/lpebody/gcj/2011_q/", "b").run()
  36.  
  37.  
  38.  
Not running #stdin #stdout 0s 0KB
stdin
Standard input is empty
stdout
Standard output is empty