需要注意Python不会像cpp的map一样自动初始化未被访问过的元素。
n = int(input()) dic = {} for _ in range(n): x,y = list(map(int,input().split())) dic[x] = dic.get(x,0) + y for x,y in sorted(dic.items()): print(x,y)
#牛客春招刷题训练营# + 链接