题解 | #字符统计#

字符统计

https://www.nowcoder.com/practice/c1f9561de1e240099bdb904765da9ad0

while True:
    try:
        strings = input()
        dict_char = {}
        for i in strings:
            dict_char[i] = strings.count(i)
        # print(dict_char)
        dict_char_sorted = sorted(dict_char.items(), key=lambda x: x[1], reverse=True)
        # print(dict_char_sorted)
        char_counts = []
        for j in dict_char_sorted:
            if j[1] not in char_counts:
                char_counts.append(j[1])
        # print(char_counts)
        chars = []
        for k in char_counts:
            temp = []
            for v in dict_char_sorted:
                if v[1] == k:
                    temp.append(v[0])
            chars.append(temp)
        # print(chars)
        result = ''
        for x in chars:
            result += ''.join(sorted(x))
        print(result)

    except:
        break

全部评论

相关推荐

评论
点赞
收藏
分享

创作者周榜

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