在一行上输入一个长度为
、由小写字母和数字构成的字符串
。
在一行上输出一个字符串,代表按频次统计后的结果。
aaddccdc
cda
在这个样例中,字符
和
出现的次数最多,均为
次,而前者 ASCII 码更小,因此先输出。
input_str = input() statistics = {} for char in input_str: if char not in statistics: statistics[char] = 1 else: statistics[char] += 1 sorted_char = sorted(statistics.items(), key=lambda item: (-item[1], ord(item[0]))) output = "" for i in range(len(sorted_char)): output += sorted_char[i][0] print(output)
a = input() dic = {} over = [] result = "" for i in a: if i not in over: over.append(i) if a.count(i) not in dic: dic[a.count(i)] = [i] else: dic[a.count(i)].append(i) keys = list(dic.keys()) keys.sort() keys.reverse() for i in keys: dic[i].sort() for m in dic[i]: result += m print(result)
s=input() s_new='' for c in s: if c not in s_new: s_new=s_new+c s_new=list(s_new) n=len(s_new) for i in range(n): for j in range(n-i-1): if s.count(s_new[j])<s.count(s_new[j+1]): s_new[j],s_new[j+1]=s_new[j+1],s_new[j] elif s.count(s_new[j])==s.count(s_new[j+1]): if s_new[j]>s_new[j+1]: s_new[j],s_new[j+1]=s_new[j+1],s_new[j] for c in s_new: print(c,end='')
s=input() d={} for i in s: if i in d.keys(): d[i]+=1 else: d[i]=1 l=sorted(d.items(),key=lambda x :x[0]) l=sorted(l,key=lambda x :x[1],reverse=True) for k,v in l: print(k,end='')
while True: try: s=input() d={} for i in str(s): if i in d.keys(): d[i]+=1 elif i not in d.keys(): d[i]=1 for key, value in sorted(sorted(d.items()),key=lambda x:x[1], reverse=True): print(key,end='') except: break
a=input() dic1={} for i in a: if i not in dic1.keys(): dic1[i]=1 else : dic1[i]=dic1[i]+1 orcdic=sorted(dic1.items(),key = lambda x:ord(x[0])) orcdic1= sorted(orcdic,key = lambda x:x[1],reverse=True) orcdic2=dict(orcdic1) print(''.join(orcdic2.keys()))