数据范围:字符串长度满足
数据范围:字符串长度满足
一个只包含小写英文字母和数字的字符串。
一个字符串,为不同字母出现次数的降序表示。若出现次数相同,则按ASCII码的升序输出。
aaddccdc
cda
样例里,c和d出现3次,a出现2次,但c的ASCII码比d小,所以先输出c,再输出d,最后输出a.
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()))
while True: try: str1 = input() if str1.isalnum() and 1 <= len(str1) <= 1000: arr1 = list(set(list(str1))) # 新建字典,读取到每个字符在字符串中的数量 dic = {} for x in arr1: dic[x] = str1.count(x) # 新建数组,存放每个字符的数量,去重后倒序排列 arr2 = [] for y in dic.values(): arr2.append(y) arr2 = list(set(arr2)) arr2.sort(reverse=True) # 新建字典,将数量作为keys,多个字母作为字符串放入value里面 dic2 = {} for n in arr2: str2 = "" for m in dic.keys(): if dic.get(m) == n: str2 = str2 + m dic2[n] = str2 # 打印排序结果,如果value长度大于1,需要进行ASCII码排序 for val in dic2.values(): if len(val) == 1: print(val, end="") elif len(val) > 1: arr3 = list(map(ord, list(val))) arr3.sort() arr3 = list(map(chr, arr3)) for v in arr3: print(v, end="") break except: break