用python很方便就能解决这道题:字典+zip()。
可能有更好的方案。
right_to_left = {}
a1 = ['`'] + [str(digit) for digit in range(1, 10)] + ['0', '-', '=']
a1 = dict(zip(a1[1:], a1[:-1]))
a2 = ['~', '!', '@', '#', '$', '%', '^', '&', '*', '(', ')', '_', '+']
a2 = dict(zip(a2[1:], a2[:-1]))
right_to_left.update(a1)
right_to_left.update(a2)
b1 = ['Q', 'W', 'E', 'R', 'T', 'Y', 'U', 'I', 'O', 'P', '[', ']', '\\']
b1 = dict(zip(b1[1:], b1[:-1]))
b2 = ['P', '{', '}', '|']
b2 = dict(zip(b2[1:], b2[:-1]))
right_to_left.update(b1)
right_to_left.update(b2)
c1 = ['A', 'S', 'D', 'F', 'G', 'H', 'J', 'K', 'L', ';', "'"]
c1 = dict(zip(c1[1:], c1[:-1]))
c2 = ['L', ':', '"']
c2 = dict(zip(c2[1:], c2[:-1]))
right_to_left.update(c1)
right_to_left.update(c2)
d1 = ['Z', 'X', 'C', 'V', 'B', 'N', 'M', ',', '.', '/']
d1 = dict(zip(d1[1:], d1[:-1]))
d2 = ['M', '<', '>', '?']
d2 = dict(zip(d2[1:], d2[:-1]))
right_to_left.update(d1)
right_to_left.update(d2)
right_to_left.update({' ': ' '})
while True:
try:
line = input()
if line == '':
break
ans = ''
for i in range(len(line)):
ans = ans + right_to_left[line[i]]
print(ans)
except:
break