感谢出色的Cristian Ciupitu,我的最终解决方案行之有效。
x = input()NUM_LETTERS = 26 #Can't import modules I'm using a web based grader/compilerdef SpyCoder(S, N): y = "" for i in S: if(i.isupper()): x = ord(i) x += N if x > ord('Z'): x -= NUM_LETTERS elif x < ord('A'): x += NUM_LETTERS y += chr(x) else: y += " " return ydef GoodnessFinder(S): y = 0 for i in S: if i.isupper(): x = ord(i) x -= ord('A') y += letterGoodness[x] else: y += 1 return ydef GoodnessComparer(S): goodnesstocompare = GoodnessFinder(S) goodness = 0 v = '' best_v = S for i in range(0, 26): v = SpyCoder(S, i) goodness = GoodnessFinder(v) if goodness > goodnesstocompare: best_v = v goodnesstocompare = goodness return best_vprint(GoodnessComparer(x))
多谢您的协助!
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)