题解 | #合并表记录#
合并表记录
http://www.nowcoder.com/practice/de044e89123f4a7482bd2b214a685201
n = int(input())
d = {} # 使用一个字典存储合并后的键值对
for _ in range(n):
i = input().split(" ")
index, value = int(i[0]), int(i[1])
d[index] = d.get(index, 0) + value # 相同key的value值相加
for k in sorted(d.keys()): # 遍历排序后的键,输出键值对
print(f"{k} {d[k]}")