题解 | #字符串合并处理#
字符串合并处理
https://www.nowcoder.com/practice/d3d8e23870584782b3dd48f26cb39c8f
from re import split def union(str1, str2): new_str = str1 + str2 return new_str def transform_1(str): ls_odd = [] ls_even = [] for i in range(len(str)): if i % 2 == 0: ls_even.append(str[i]) else: ls_odd.append(str[i]) new_ls_odd = sorted(ls_odd) new_ls_event = sorted(ls_even) new_str = [] for i in range(len(str)): if i % 2 == 0: new_str.append(new_ls_event.pop(0)) else: new_str.append(new_ls_odd.pop(0)) return ("".join(new_str)) def transform_2(str): new_str = [] for c in str: if '0'<=c<='9' or 'a'<=c<='f' or 'A'<=c<='F': dec_num = int(c, 16) bin_num = bin(dec_num)[2:].zfill(4)[::-1] new_bin_num = int(bin_num,2) res = hex(new_bin_num)[2] # print(res) if 'a'<=res<='z': new_str.append(res.upper()) else: new_str.append(res) else: new_str.append(c) return ("".join(new_str)) str = input().split() str_1 = union(str[0],str[1]) str_2 = transform_1(str_1) str_3 = transform_2(str_2) print(str_3)