文章目录
开源项目热度榜单
- 开发者对每个开源项目,可以关注(watch)、收藏(star)、复制(fork)、提问题(issue)、提合并请求(MR)等。
- 热度值H = 权重*watch + 权重*star + 权重*fork + 权重*issue + 权重*MR;
- 根据热度值H降序排序,对热度值相等的按照项目名转为小写字母后的字典序排序;
输入描述:
第一行为项目个数n
第二行为watch star fork issue MR维度的权重;
后n行表示每个项目的数据,格式为:项目名 watch star fork issue MR
输出描述:
排序后逐行输出项目名称
示例1
输入:
4
8 6 2 8 6
camila 66 70 46 158 80
victoria 94 76 86 189 211
anthony 29 17 83 21 48
emily 53 97 1 19 218
输出:
victoria
camila
emily
anthony
思路:
- 自定义排序
python
n = int(input().strip())
weights = list(map(int, input().strip().split()))
alist = []
for i in range(n):
temp = input().strip().split()
name = temp.pop(0)
dims = [int(e) for e in temp]
# 计算热度h
h = 0
for j in range(len(weights)):
h += weights[j] * dims[j]
alist.append((name, h))
# 排序
alist.sort(key=lambda i: (-i[1], i[0].lower()))
for t in alist:
print(t[0])