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

字符串合并处理

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

```numto = {}
numto["1"] = ["8"]
numto["2"] = ["4"]
numto["3"] = ["C"]
numto["4"] = ["2"]
numto["5"] = ["A"]
numto["6"] = ["6"]
numto["7"] = ["E"]
numto["8"] = ["1"]
numto["9"] = ["9"]
numto["A"] = ["5"]
numto["B"] = ["D"]
numto["C"] = ["3"]
numto["D"] = ["B"]
numto["E"] = ["7"]
numto["F"] = ["F"]
numto["a"] = ["5"]
numto["b"] = ["D"]
numto["c"] = ["3"]
numto["d"] = ["B"]
numto["e"] = ["7"]
numto["f"] = ["F"]
while True:
    try:
        a =input()
        b = a.split(" ")
        c = b[0]+b[1]
        num = len(c)
        c1 = []
        c2 = []
        for i in range(num):
            if i % 2 == 0:
                c1.append(c[i])
            else:
                c2.append(c[i])
        c1.sort()
        c2.sort()
        new_a = []
        count = 0
        count1 = 0
        for j in range(num):
            if j % 2 == 0:
                new_a.append(c1[count])
            else:
                new_a.append(c2[count])
                count = count + 1

        new_b = []
        for k in range(num):
            try:
                new_b += numto[new_a[k]]
            except:
                new_b += new_a[k]
        bbb = ''
        bbb = bbb.join(new_b)
        print(bbb)
    except:
        break
全部评论

相关推荐

object3:开始给部分🌸孝子上人生第一课了
点赞 评论 收藏
分享
拒绝无效加班的小师弟很中意你:求职意向没有,年龄、课程冗余信息可以删掉,需要提升项目经历。排版需要修改。
点赞 评论 收藏
分享
点赞 收藏 评论
分享
牛客网
牛客企业服务