1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
| # 定义一个函数,用来计算单词的综合评分
def average_score(word_scores):
# 使用字典来存储单词和对应的评分列表
word_dict = {}
for word, score in word_scores:
# 如果单词已经在字典中,就将评分添加到列表中
if word in word_dict:
word_dict[word].append(score)
# 否则,就创建一个新的键值对,值为一个只包含评分的列表
else:
word_dict[word] = [score]
# 使用列表推导式来计算每个单词的平均评分,返回一个列表
return [(word, sum(scores) / len(scores)) for word, scores in word_dict.items()]
# 读取输入数据,转换为列表
T = int(input()) # 数据组数
for t in range(T): # 循环处理每一组数据
N = int(input()) # 每组数据的人数
word_scores = [] # 每组数据的单词和评分列表
for n in range(N * 10): # 循环读取每个人的10个单词和评分
word, score = input().split() # 分割单词和评分
score = int(score) # 转换评分为整数
word_scores.append((word, score)) # 将单词和评分的元组添加到列表中
# 调用函数,得到每个单词的平均评分列表
avg_scores = average_score(word_scores)
# 使用min函数,按照平均评分的大小,找出最小的元素,返回一个元组
min_word, min_score = min(avg_scores, key=lambda x: x[1])
# 输出最简单的单词
print(min_word)
|