题解 | 字符串变形
字符串变形
https://www.nowcoder.com/practice/c3120c1c1bc44ad986259c0cf0f0b80e
# # 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 # # # @param s string字符串 # @param n int整型 # @return string字符串 # """ 关键点: ord 的使用 判断字符的ascii 码 大小写字母 字符串数组的逆序: s=s[::-1] """ class Solution: def trans(self , s: str, n: int) -> str: # write code here line="" for ch in s: ret_ch=self.func(ch) line+=str(ret_ch) #分割 st_list=list(line.split(" ")) st_list=st_list[::-1] res=list() return " ".join(st_list) # 用空格隔开 def func(self,ch): if ord("A")<=ord(ch)<=ord("Z"): return ch.lower() if ord("a")<= ord(ch)<=ord("z"): return ch.upper() else: return ch