牛客网-华为题库-合并字符串

详细题目信息参见:

HJ30 合并字符串处理

import sys


def fun(c):
    """
    对16进制字符进行翻转转换
    """
    to2 = format(int(c, 16), "b").rjust(4, "0")
    to16 = format(int(to2[::-1], 2), "X")
    return to16


while True:
    try:
        s1, s2 = input().split()
        s = list(s1 + s2)
        hexs = "0123456789abcdefABCDEF"

        # 奇子串排序
        s[::2] = sorted(s[::2])
        # 偶子串排序
        s[1::2] = sorted(s[1::2])

        for i in range(len(s)):
            if s[i] in hexs:
                s[i] = fun(s[i])

        print("".join(s))
    except:
        break

Add a Comment

邮箱地址不会被公开。 必填项已用*标注

此站点使用Akismet来减少垃圾评论。了解我们如何处理您的评论数据