题解 | #字符串加解密#
字符串加解密
https://www.nowcoder.com/practice/2aa32b378a024755a3f251e75cbf233a
import sys import string string_lower_list = list(string.ascii_lowercase) string_upper_list = list(string.ascii_uppercase) nums_list = [str(each) for each in range(0, 10)] def encry_str(word): res = [] for each in word: if each in string_lower_list: container = string_lower_list elif each in string_upper_list: container = string_upper_list else: container = nums_list if container.index(each) == len(container) - 1: want = container[0] else: want = container[container.index(each) + 1] if want in string_lower_list: res.append(want.upper()) elif want in string_upper_list: res.append(want.lower()) else: res.append(want) return "".join(res) def deencry_str(word): res = [] for each in word: if each in string_lower_list: container = string_lower_list elif each in string_upper_list: container = string_upper_list else: container = nums_list if container.index(each) == 0: want = container[-1] else: want = container[container.index(each) - 1] if want in string_lower_list: res.append(want.upper()) elif want in string_upper_list: res.append(want.lower()) else: res.append(want) return "".join(res) count = 0 for line in sys.stdin: if count == 0: encry = line.split()[0] res = encry_str(encry) print(res) if count == 1: deencry = line.split()[0] res = deencry_str(deencry) print(res) count += 1