HJ23 删除字符串中出现次数最少的字符

思路:

step1:输入一组字符串s,同时创建一个新的字典dic;
step2:遍历字符串s,如果元素在字典里,dic[i]累加次数,否则,dic[i]为1;
step3:使得MIN为出现最小次数的值;
step4:重新遍历s,如果i在字典中记录的次数等于MIN,则在原字符串s中用空字符替换;
step5:输出打印s

代码如下:

s = input()
dic = {}
for i in s:
    if i in dic:
        dic[i] += 1
    else:
        dic[i] = 1
MIN = min(dic.values())
for i in s:
    if dic[i] == MIN:
        s = s.replace(i,'')
print(s)