题解 | #字符串合并处理#
字符串合并处理
https://www.nowcoder.com/practice/d3d8e23870584782b3dd48f26cb39c8f
import re str1, str2 = list(input().split()) str_all = list(str1 + str2) str_all[::2] = sorted(str_all[::2]) #奇数位排序 str_all[1::2] = sorted(str_all[1::2]) #偶数位排序 result = "" for n in str_all: if re.search(r'[0-9A-Fa-f]', n): # 如果字符在特殊字符范围内 n = bin(int(n, 16))[2:].rjust(4, '0')[::-1] #十六进制转二进制,去掉前两位,倒序 n = hex(int(n, 2))[2:].upper() #二进制转十六进制,去掉前两位,大写 result += n print(result)