题解 | 字符串合并处理

字符串合并处理

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

s0 = input().split()
s = s0[0]
t = s0[-1]
u = s + t

# sort
u_itere = enumerate(u)
u_itero = enumerate(u)
u_even = sorted([c for i, c in filter(lambda x: x[0] % 2 == 0, u_itere)])
u_odd = sorted([c for i, c in filter(lambda x: x[0] % 2 == 1, u_itero)])

u_sorted = ''
idx1 = idx2 = 0
for i in range(len(u)):
    if i % 2 == 0:
        u_sorted += u_even[idx1]
        idx1 += 1
    else:
        u_sorted += u_odd[idx2]
        idx2 += 1
# 2_step
u = ''
for c in u_sorted:
    if c.isdigit() or ('a' <= c <= 'f') or ('A' <= c <= 'F'):
        num = int(c, 16)
        bin_str = format(num, '04b')[::-1]
        reversed_num = int(bin_str, 2)
        c = format(reversed_num, 'X')
    u += c

print(u)

全部评论

相关推荐

评论
点赞
收藏
分享

创作者周榜

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