【題解】ZeroJudge e975: 3. 情書解密 (Love)

【題目敘述】https://zerojudge.tw/ShowProblem?problemid=e975

Python code (credit: Amy Chou)

S = input()
for k in range(26):
    new = ""
    for c in S:
        # 只需解密英文字母
        if (c >= "a" and c <= "z"):
            new += chr((ord(c) - ord("a") + k) % 26 + ord("a"))
        elif (c >= "A" and c <= "Z"):
            new += chr((ord(c) - ord("A") + k) % 26 + ord("A"))
        else:
            new += c
        
    if ("love" in new) or ("Love" in new):
        print(k)
        break

分享本文 Share with friends