鱼C论坛

 找回密码
 立即注册
123
返回列表 发新帖
楼主: zltzlt

[已解决]Python:每日一题 320

[复制链接]
发表于 2020-2-3 12:04:39 | 显示全部楼层
  1. def Kstart(self, aString):
  2.         
  3.     counts=[]
  4.     times=0
  5.     bString= "".join(list(set(aString)))
  6.     for each in bString:
  7.         counts.append(aString.count(each))
  8.     counts.sort(reverse=True)
  9.         
  10.     i=1
  11.         
  12.     while i<len(counts):
  13.         while counts[i] in counts[:i]:
  14.             times+=1
  15.             counts[i]-=1
  16.             if counts[i]<=0:
  17.                 times+=sum(counts[i+1:])
  18.                 return times
  19.         i+=1
  20.     return times
复制代码
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2020-3-21 18:31:11 | 显示全部楼层
  1. #不重复个数字母
  2. def fun320(str):
  3.     dic = {}
  4.     for each in str:
  5.         dic[each] = str.count(each)
  6.     value_lst = []
  7.     for value in dic.values():
  8.         value_lst.append(value)
  9.     l = len(value_lst)
  10.     value_lst.sort(reverse = True)
  11.     count = 0
  12.     #print(value_lst)
  13.     for i in range(l):
  14.         if i < l-1:
  15.             if value_lst[i] <= value_lst[i+1] and value_lst[i] >= 1:
  16.                 count += value_lst[i+1]-value_lst[i]+1
  17.                 value_lst[i+1] = value_lst[i] - 1
  18.                 if value_lst[i] == 0:
  19.                     count +=value_lst[i+1]
  20.                     value_lst[i+1] = 0   
  21.     return count
复制代码
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2020-10-5 11:44:09 | 显示全部楼层
  1. def fun320(x):
  2.     result = 0
  3.     count_x = []
  4.     for i in set(x):
  5.         if x.count(i) not in count_x:
  6.             count_x.append(x.count(i))
  7.         else:
  8.             count_i = x.count(i)
  9.             while True:
  10.                 result += 1
  11.                 count_i -= 1
  12.                 if count_i not in count_x and count_i:
  13.                     count_x.append(count_i)
  14.                     break
  15.                 elif not count_i:
  16.                     break
  17.     return result
复制代码
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|手机版|Archiver|鱼C工作室 ( 粤ICP备18085999号-1 | 粤公网安备 44051102000585号)

GMT+8, 2025-6-28 00:56

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表