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

字符串合并处理

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

def conv(c):
    res=''
    if (c.isdigit() and 0<= int(c) <= 9) or (c.isalpha() and 'a' <= c.lower() <= 'f'):
        res = hex(int(bin(int(c,16))[2:].rjust(4,'0')[::-1],2))[2:]
    else:
        res = c
    return res.upper() if (res.isalpha() and  'a' <= res.lower() <= 'f') else res
instr = list("".join(input().split()))
ou = []
ji = []
dst= []
for i,c in enumerate(instr):
    if i % 2 == 0:
        ou.append(c)
    else:
        ji.append(c)
ou.sort()
ji.sort()
for i in range(0,len(instr)):
    if i % 2 == 0:
        dst.append(ou.pop(0))
    else:
        dst.append(ji.pop(0))
resulst = ''
for c in dst:
    print(conv(c),end="")

全部评论

相关推荐

评论
点赞
收藏
分享

创作者周榜

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