题解 | #字符串合并处理#
字符串合并处理
https://www.nowcoder.com/practice/d3d8e23870584782b3dd48f26cb39c8f
str1,str2 = input().split() str_merge = str1 + str2 str1_sort = '' str2_sort = '' str_result = '' Odd_number = 0 Even_number = 0 result = '' for i in range(len(str_merge)): if i%2 == 0: str1_sort += str_merge[i] else: str2_sort += str_merge[i] for i in range(len(str_merge)): if i%2 == 0: str_result += sorted(str1_sort)[Odd_number] Odd_number += 1 else: str_result += sorted(str2_sort)[Even_number] Even_number += 1 for i in str_result: if i.isalpha(): if not ord(i.lower())>ord('f'): i = ord(i.lower())-ord('a')+10 i = f'{int(i):04b}'[::-1] if int(i,2) < 10: result += str(int(i,2)) else: result += chr(int(i,2)+ord('A')-10) else: result += i else: i = f'{int(i):04b}'[::-1] if int(i,2) < 10: result += str(int(i,2)) else: result += chr(int(i,2)+ord('A')-10) print(result)