题解 | #合并表记录#
合并表记录
https://www.nowcoder.com/practice/de044e89123f4a7482bd2b214a685201
import sys
n = int(input())
dic = {}
for i in range(n):
key,value = map(int,input().split()) #数值转换
#dic[key] = dic.get(key,0) + value
if key not in dic.keys(): #若从来没出现过,新增
dic[key] = value
else: #若出现过,求和
dic[key] += value
for each in sorted(dic): #排序
print(each, dic[each])

查看23道真题和解析