华为机试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)
相关推荐
金銀銅鐵17 小时前
[Python] 从《千字文》中随机挑选汉字
后端·python
cup111 天前
[技术复盘] Windows Python 打包实战:Nuitka 环境踩坑总结与 CI 自动化构建全指南
python·ai·环境变量·ci·nuitka·skill
aqi001 天前
15天学会AI应用开发(七)有了大模型为什么还要引入RAG
人工智能·python·大模型·ai编程·ai应用
金銀銅鐵1 天前
用 Python 实现 Take-Away 游戏
python·游戏
copyer_xyf1 天前
Agent 流程编排
后端·python·agent
copyer_xyf1 天前
Agent RAG
后端·python·agent
copyer_xyf1 天前
【RAG】向量数据库:milvus
后端·python·agent
copyer_xyf1 天前
Agent 记忆管理
后端·python·agent
星云穿梭2 天前
用Python写一个带图形界面的学生管理系统——完整教程
python