题解 | #字符串合并处理#

字符串合并处理

https://www.nowcoder.com/practice/d3d8e23870584782b3dd48f26cb39c8f

str1, str2 = input().split()

str3 = list(str1+str2)

str3[::2] = sorted(str3[::2])
str3[1::2] = sorted(str3[1::2])

res = []
for i in str3:
    if i in '0123456789abcdefABCDEF':
        tmp = bin(int(i,16))[2:].rjust(4,'0')[::-1]  # 按照16进制进解析成二进制
        r = hex(int(tmp,2))[2:].upper() # 按照二进制转换成16进制
        res.append(r)
    else:
        res.append(i)

for i in res:
    print(i,end='')

全部评论

相关推荐

浩浩没烦恼:一二面加起来才一个小时? 我一面就一个小时多了
点赞 评论 收藏
分享
评论
1
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务