华为机试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)
相关推荐
明月_清风2 小时前
Python 内存手术刀:sys.getrefcount 与引用计数的生死时速
后端·python
明月_清风2 小时前
Python 消失的内存:为什么 list=[] 是新手最容易踩的“毒苹果”?
后端·python
Flittly17 小时前
【从零手写 ClaudeCode:learn-claude-code 项目实战笔记】(3)TodoWrite (待办写入)
python·agent
千寻girling21 小时前
一份不可多得的 《 Django 》 零基础入门教程
后端·python·面试
databook1 天前
探索视觉的边界:用 Manim 重现有趣的知觉错觉
python·动效
明月_清风1 天前
Python 性能微观世界:列表推导式 vs for 循环
后端·python
明月_清风1 天前
Python 性能翻身仗:从 O(n) 到 O(1) 的工程实践
后端·python
helloweilei2 天前
python 抽象基类
python
用户8356290780512 天前
Python 实现 PPT 转 HTML
后端·python
zone77392 天前
004:RAG 入门-LangChain读取PDF
后端·python·面试