题解 | 字符统计

def string_count(n):
    letter_dict = {}
    for i in n:
        if i in letter_dict:
            letter_dict[i] += 1
        else:
            letter_dict[i] = 1

    new_w_dict = sorted(letter_dict.items(), key=lambda x: (-x[1], x[0]))
    finall = []
    for item in new_w_dict:
        finall.append(item[0])
    return ''.join(finall)

n = input().strip()
print(string_count(n))
        

全部评论

相关推荐

点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
正在热议
更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务