实现删除字符串中出现次数最少的字符,若出现次数最少的字符有多个,则把出现次数最少的字符都删除。输出删除这些单词后的字符串,字符串中其它字符保持原来的顺序。
数据范围:输入的字符串长度满足 1≤n≤20 ,保证输入的字符串中仅出现小写字母
输入:aabcddd
输出:aaddd
import sys
def count_num(s):
char_count = {}
for char in s:
char_count[char] = char_count.get(char, 0) + 1
return char_count
for line in sys.stdin:
a = line.split()
char_count = count_num(a[0])
min_value = min(char_count.values())
min_keys = [key for key, value in char_count.items() if value == min_value]
b = a[0]
for i in min_keys:
b = b.replace(i,'')
print(b)