博主头像
Q的小站

思想无界,文字有声

字符排序

无技术含量,纯为复制粘贴方便👍

s=''
ls=[]
num=[]
for i in s:
    pos=-1
    for j in range(len(ls)):
        if ls[j]==i:
            pos=j
            break
    if pos==-1:
        ls.append(i)
        num.append(1)
    else:
        num[pos]+=1
for i in range(len(ls)):
    for j in range(len(ls)-i-1):
        if num[j]<num[j+1]:
            num[j],num[j+1]=num[j+1],num[j]
            ls[j],ls[j+1]=ls[j+1],ls[j]
for i in ls:
    print(i,end='')
字符排序
https://blog.colix.cn/index.php/%E6%96%87%E6%9C%AC%E5%A4%84%E7%90%86/7.html
本文作者 Q
发布时间 2024-07-01
许可协议 CC BY-NC-SA 4.0
发表新评论