1. 问题描述:
给定一个由大小写字母构成的字符串,请你对该字符串进行如下处理:
将所有大写字母替换为相应的小写字母。
删除其中的所有元音字母。
在每个辅音字母前面插入一个 .。
字母 a,o,y,e,u,i 为元音字母,其余字母均为辅音字母。注意,y 其实是半元音字母,在本题中规定其为元音字母。
输入格式
一个由大小写字母构成的字符串。
输出格式
输出处理后的字符串。
保证处理后的字符串不为空。
数据范围
所有测试点满足,字符串长度范围 [1,100]。
输入样例1:
tour
输出样例1:
.t.r
输入样例2:
aBAcAba
输出样例2:
.b.c.b
来源:https://www.acwing.com/problem/content/description/4218/
2. 思路分析:
分析题目可以知道根据题目的描述模拟整个过程即可。
3. 代码如下:
class Solution:
def process(self):
s = input()
# 初始化set集合中的元素为元音字母
a = {"a", "e", "y", "i", "o", "u", "A", "E", "I", "O", "U", "Y"}
res = ""
for c in s:
if c in a: continue
elif "A" <= c <= "Z":
res += "." + chr(ord(c) - ord("A") + ord("a"))
else: res += "." + c
return res
if __name__ == '__main__':
print(Solution().process())