题解 | #字符串合并处理#
字符串合并处理
http://www.nowcoder.com/practice/d3d8e23870584782b3dd48f26cb39c8f
import sys checkc = "0123456789abcdefABCDEF" #转换函数 #先转成数值,再转成二进制表示,倒序,转成数值,再从表里找到字符 def process(c): if c in checkc: if c.isupper(): c = c.lower() index = checkc.find(c) c = bin(index)[2:] c = checkc[int(c.rjust(4, '0')[::-1],2)] if c.islower(): c = c.upper() return c while True: try: s = input().strip().replace(" ", "") s1 = "" s2 = "" for i in range(len(s)): if i % 2 == 0: s1 += s[i] else: s2 += s[i] #分别排序 s1 = sorted(s1) s2 = sorted(s2) # print(s1) # print(s2) sn = "" #拼接 for i in range(len(s)): if i % 2 == 0: sn += s1[0] s1 = s1[1:] else: sn += s2[0] s2 = s2[1:] # print(sn) result = "" for c in sn: result += process(c) print(result) except: # print(sys.exc_info()) break