3475. 简单密码
摘要
Title: 3475. 简单密码
Tag: 字母
Memory Limit: 64 MB
Time Limit: 1000 ms
Powered by:NEFU AB-IN
3475. 简单密码
-
题意
Julius Caesar 曾经使用过一种很简单的密码。
对于明文中的每个字符,将它用它字母表中后 5 位对应的字符来代替,这样就得到了密文。
比如字符 A用 F来代替。
如下是密文和明文中字符的对应关系。
密文 A B C D E F G H I J K L M N O P Q R S T U V W X Y Z
明文 V W X Y Z A B C D E F G H I J K L M N O P Q R S T U
你的任务是对给定的密文进行解密得到明文。
你需要注意的是,密文中出现的字母都是大写字母。
密文中也包括非字母的字符,对这些字符不用进行解码。 -
思路
将字母转换为字典序,减去5的同时,加上26并取模
-
代码
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48# import
import sys, math
from collections import Counter, deque
from heapq import heapify, heappop, heappush, nlargest, nsmallest
from bisect import bisect_left, bisect_right
from datetime import datetime, timedelta
from string import ascii_lowercase, ascii_uppercase
class sa:
def __init__(self, x, y):
self.x = x
self.y = y
def __lt__(self, x):
pass
# Final
N = int(1e3 + 10)
INF = int(2e9)
# Define
sys.setrecursionlimit(INF)
read = lambda: map(int, input().split())
LTN = lambda x: ord(x.upper()) - 65 # A -> 0
NTL = lambda x: ascii_uppercase[x] # 0 -> A
# —————————————————————Division line ——————————————————————
while True:
try:
st = input()
if st == 'ENDOFINPUT':
break
s = input()
ed = input()
for i in s:
if i >= 'A' and i <= 'Z':
ii = NTL((LTN(i) - 5 + 26) % 26)
print(ii, end="")
else:
print(i, end="")
print()
except:
break