题解 | #字符串合并处理#
字符串合并处理
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="")
