华为机试HJ21简单密码

华为机试HJ21简单密码

题目:

现在有一种密码变换算法。九键手机键盘上的数字与字母的对应: 1--1, abc--2, def--3, ghi--4, jkl--5, mno--6, pqrs--7, tuv--8 wxyz--9, 0--0,把密码中出现的小写字母都变成九键键盘对应的数字,如:a 变成 2,x 变成 9.而密码中出现的大写字母则变成小写之后往后移一位,如:X ,先变成小写,再往后移一位,变成了 y ,例外:Z 往后移是 a 。数字和其它的符号都不做变换。数据范围: 输入的字符串长度满足 1≤n≤100

想法:

根据上述规则找到对应的变换并输出

复制代码
input_str = input()

l1 = ['a','b','c']
l2 = ['d','e','f']
l3 = ['g','h','i']
l4 = ['j','k','l']
l5 = ['m','n','o']
l6 = ['p','q','r','s']
l7 = ['t','u','v']
l8 = ['w','x','y','z']

result = ""

for i in input_str:
    if i in l1:
        result += "2"
    elif i in l2:
        result += "3"
    elif i in l3:
        result += "4"
    elif i in l4:
        result += "5"
    elif i in l5:
        result += "6"
    elif i in l6:
        result += "7"
    elif i in l7:
        result += "8"
    elif i in l8:
        result += "9"
    elif i < "Z" and i >= "A":
        result += chr(ord(i) + 32 + 1)
    elif i == "Z":
        result += "a"
    else:
        result += i

print(result)
相关推荐
花酒锄作田19 小时前
Pydantic校验配置文件
python
hboot19 小时前
AI工程师第四课 - 深度学习入门
pytorch·python·神经网络
ZhengEnCi1 天前
P2M-Matplotlib折线图完全指南-从数据可视化到趋势分析的Python绘图利器
python·matlab·数据可视化
ZhengEnCi1 天前
P2L-Matplotlib饼图完全指南-从数据可视化到图表定制的Python绘图利器
python·matlab
曲幽1 天前
你的REST接口还在“过度投喂”数据吗?——FastAPI + GraphQL实战避坑指南
python·fastapi·web·graphql·route·cors·rest·strawberry
用户8358086187911 天前
基于 Self-RAG 与列表级重排序的进阶 RAG 系统设计与实现
python
Warson_L2 天前
Python `Annotated` 与 LangGraph Reducer 学习笔记
python
韩师傅2 天前
海天线算法的前世今生
python·计算机视觉
韩师傅2 天前
当你的甲方设备过烂,要如何快速出效果?
python·计算机视觉
Warson_L2 天前
LangGraph的MessageState and HumanMessage
python