题解 | #字符串合并处理#
字符串合并处理
http://www.nowcoder.com/practice/d3d8e23870584782b3dd48f26cb39c8f
import sys
import re
def encrypt(x):
if re.search(r'[a-fA-F0-9]', x):
b = bin(int(x, 16))[2:].rjust(4, "0")[::-1]
h = hex(int(b, 2))[2:].upper()
return h
else:
return x
for line in sys.stdin:
# step 1
a = list(line.strip().replace(" ", ""))
# step 2
a[::2] = sorted(a[::2])
a[1::2] = sorted(a[1::2])
# step 3
print("".join([encrypt(i) for i in a]))