实现删除字符串中出现次数最少的字符,若出现次数最少的字符有多个,则把出现次数最少的字符都删除。输出删除这些单词后的字符串,字符串中其它字符保持原来的顺序。
数据范围:输入的字符串长度满足 ,保证输入的字符串中仅出现小写字母
字符串只包含小写英文字母, 不考虑非法输入,输入的字符串长度小于等于20个字节。
删除字符串中出现次数最少的字符后的字符串。
aabcddd
aaddd
""" 1. 计算每个字符出现的次数 2. replace """ s = input() letters = [] # 获取元素范围 sl = list(set(list(s))) # 比较字母出现次数和最小数 for l in sl: if s.count(l) == min([s.count(i) for i in sl]): letters.append(l) # 替换为空 for letter in letters: s = s.replace(letter,'') print(s)
lis = [i for i in input()] liscount = sorted([lis.count(i) for i in set(lis)]) print(*[i for i in lis if lis.count(i) != liscount[0]],sep='')
import sys strs = input() ls = [] for s in strs: ls.append(s) dic = {} for i in ls: if i not in dic.keys(): dic[i] = 1 else: dic[i] +=1 sels = list(set(ls)) for i in range(len(sels)): for j in range(i+1,len(sels)): if dic[sels[i]]>=dic[sels[j]]: sels[i],sels[j] = sels[j],sels[i] else: pass tmls = [] for i in range(len(sels)): if dic[sels[i]]==dic[sels[0]]: tmls.append(sels[i]) else: break for i in ls: if i not in tmls: print(i,end='')
S = input() T ={} for s in S: if s in T: T[s] += 1 else: T[s] = 1 value_min = min(T.values()) T_min = [] for key, value in T.items(): if value == value_min: T_min.append(key) for s in S: if s not in T_min: print(s, end='')
import sys str = input() list_char = [] list_char_count = [] for i in range(len(str)): if str[i] not in list_char: list_char.append(str[i]) list_char_count.append(str.count(str[i])) #以上步骤可以实现一个列表,一个计入符号,一个计入数量 list_char_count_min = sorted(list_char_count)[0] #sorted得到新建的对数量进行排序的list,第一个数一定是最少的那个 list_char_count_min_index = [] for i in range(len(list_char_count)): if list_char_count[i] == list_char_count_min: list_char_count_min_index.append(int(i)) #记录最少数量符号的地址,下一步创建包含最少数量符号的list list_char_count_min_char = [list_char[i] for i in list_char_count_min_index] for i in range(len(str)): #当str中的符号不属于最少数量符号list中的成员就输出不带换行符号 if str[i] not in list_char_count_min_char: print(str[i],end='')
a = input().strip() b, m = [a[0]], a.count(a[0]) for i in set(a): n = a.count(i) if n < m: b.clear() b.append(i) m = n elif n == m: b.append(i) for i in a: if i not in b: print(i, end="")
from collections import Counter res = input() cnt = Counter(res) s = set() for k,v in cnt.items(): if v==min(cnt.values()): s.add(k) for w in s: res = res.replace(w, '') print(res)