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

字符串合并处理

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

a,b = input().split(" ")
s = str(a + b)
c = []

ls1 = []
for i in s[::2]:############奇数#3
    ls1.append(i)
ls1.sort()


ls2 = []
for j in s[1::2]:############偶数
    ls2.append(j)
ls2.sort()

m = 0
n = 0
while True:
    try:
        c.append(ls1[n])
        n += 1
        c.append(ls2[m])
        m += 1
    except:
        break

##################转换
for i in c:
    try:
        b = bin(int(i,16))[2:]############二进制开头0b不要
        if len(b) < 4:
            b = '0'*(4-len(b)) + b
        b = b[::-1]
        b = hex(int(b,2))[2:].upper()
        print(b,end="")
    except:
        print(i,end='')
print()

全部评论

相关推荐

点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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