分类:字符串
知识点:
-
字符的Unicode码 num = ord(my_char)
-
一个整数转换为一个对应的 ASCII 字符 my_char = chr(num)
题目来自【牛客】
python
import sys
def transform_password(password):
result = ""
for char in password:
if 'a' <= char <= 'c':
result += '2'
elif 'd' <= char <= 'f':
result += '3'
elif 'g' <= char <= 'i':
result += '4'
elif 'j' <= char <= 'l':
result += '5'
elif 'm' <= char <= 'o':
result += '6'
elif 'p' <= char <= 's':
result += '7'
elif 't' <= char <= 'v':
result += '8'
elif 'w' <= char <= 'z':
result += '9'
elif 'A' <= char <= 'Z':
# 特殊处理Z
if char == 'Z':
result += 'a'
else:
# ord() 用于返回一个字符的 Unicode 码点
# chr() 用于将一个整数转换为一个对应的 ASCII 字符。
result += chr(ord(char.lower()) + 1)
else:
result += char
return result
for line in sys.stdin:
password = line.strip()
result = transform_password(password)
print(result)