题解 | #字符串合并处理#
字符串合并处理
https://www.nowcoder.com/practice/d3d8e23870584782b3dd48f26cb39c8f
l_input = input().split(" ") s = l_input[0] + l_input[1] l = list(s) # 十六进制倒过来 def fhex(val): val =bin(val)[:1:-1] while len(val)<4: val+="0" return hex(int(val,2))[2].upper() # 奇偶 ji = [] ou = [] for i in range(len(l)): if i % 2: ji.append(l[i]) else: ou.append(l[i]) ji.sort() ou.sort() i_ji = 0 i_ou = 0 new_l = [] for i in range(len(l)): if i % 2: new_l.append(ji[i_ji]) i_ji += 1 else: new_l.append(ou[i_ou]) i_ou += 1 l = new_l new_l = [] for val in l: if 'a' <= val <= 'f': val = ord(val) - ord('a') + 10 new_l.append(fhex(val)) elif 'A' <= val <= 'F': val = ord(val) - ord('A') + 10 new_l.append(fhex(val)) elif '0' <= val <= '9': val = int(val) new_l.append(fhex(val)) else: new_l.append(val) print("".join(new_l))