题解 | #合并表记录#
合并表记录
http://www.nowcoder.com/practice/de044e89123f4a7482bd2b214a685201
# 先合并再排序
n = int(input())
m = {}
for i in range(n):
key, value = map(int,input().split())
if key not in m:
m[key] = value
else:
m[key] = m.get(key) + value
# 对字典中的key值排序,使用sorted()函数可对所有可迭代对象排序
# 按照格式输出
for key, value in sorted(m.items()):
print(str(key) + " " + str(m.get(key)))