使用哈希表来解决该问题,非常简单。代码如下:

while True:
    try:
        s = input()
    except:
        break
    dic = {}
    for i in s:
        if dic.get(i):
            dic[i] += 1
        else:
            dic[i] = 1
    for i in sorted(dic):
        for j in range(dic[i]):
            print(i, end='')
    print()