题解 | #字符统计#
字符统计
https://www.nowcoder.com/practice/c1f9561de1e240099bdb904765da9ad0
# 用字典存储次数,评论有牛逼操作
s = input()
d = {}
# 遍历字符串
for c in s:
# 如果字符在字典中已经存在
if c in d:
# 将它的次数加一
d[c] += 1
else:
# 将它作为键加入字典,并将它的次数设为一
d[c] = 1
# 将字典中的键值对转换成列表
l = list(d.items())
# 对列表进行排序
l.sort(key=lambda x: (-x[1], x[0]))
result = ""
for t in l:
result += t[0]
print(result)
while True:
try:
s = input()
ss = sorted(list(set(s)), key=lambda x:s.count(x)*1000-ord(x), reverse=True)
print("".join(ss))
except:
break