所属作业: hw9
数据结构: 字符串
算法: 循环
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
| n = int(input())
operation = input()
text = input()
result = ""
for char in text:
if char.isalpha():
if operation == "E":
if char.islower():
result += chr((ord(char) - ord('a') + n) % 26 + ord('a'))
else:
result += chr((ord(char) - ord('A') + n) % 26 + ord('A'))
elif operation == "D":
if char.islower():
result += chr((ord(char) - ord('a') - n) % 26 + ord('a'))
else:
result += chr((ord(char) - ord('A') - n) % 26 + ord('A'))
else:
result += char
print(result)
|