题解 | #合并表记录#
合并表记录
https://www.nowcoder.com/practice/de044e89123f4a7482bd2b214a685201
n = int(input()) d = {} # 用字典保存键和值 for _ in range(n): a, b = list(map(int,input().split())) #将输入的字符串,读成int if a in d: d[a] += b else: d[a] = b temp = sorted(d.items(), key=lambda x:x[0]) # 对字符串进行排序,是按照首字符排序的 for k, v in temp: print(k, v)