题解 | #字符统计#

字符统计

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

s = input().strip()
s2 = set(s) # 去重
c = {}  # 存 i:count(i)的键值对
d = []  # 存所有的count(i)
for i in s2:
    if s.count(i) not in c:
        c[i] = s.count(i)
    else:
        c[i] = s.count(i) + 1
d = c.values()
e = sorted(set(d), reverse=True) # 所有的count(i)去重后倒序排列
output = ''
# 获取字典c中value = count(j)的所有keys
for j in e:
    sn = sorted([key for key, value in c.items() if value == j])
    output += ''.join(sn)
print(output)

全部评论

相关推荐

哇哇的菜鸡oc:他这不叫校招offer,而是实习offer
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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