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

字符串合并处理

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

import sys





word=input().split(' ')
new_word=word[0]+word[1]

new_tem_word=list(new_word)
new_tem_word[::2]=sorted(new_tem_word[::2])
new_tem_word[1::2]=sorted(new_tem_word[1::2])
end_word=''

for i in new_tem_word:
    if '0'<=i<='9' or 'a'<=i<='f' or 'A'<=i<='F':
        if i.isdigit():
            g=bin(int(i))[2:]
            if len(g)<4:
                g=(4-len(g))*'0'+g
            g=hex(int(g[::-1],2))[2:]
            if g.isalpha():
                g=g.upper()
        else:
            g=hex(int(bin(int(i,16))[2:][::-1],2))[2:]
            if g.isalpha():
                g=g.upper()
        end_word=end_word+str(g)
    else:
        end_word=end_word+i
print(end_word)

全部评论

相关推荐

我见java多妩媚:大外包
点赞 评论 收藏
分享
11-08 17:36
诺瓦科技_HR
点赞 评论 收藏
分享
点赞 收藏 评论
分享
牛客网
牛客企业服务