题解 | #合并表记录#
合并表记录
https://www.nowcoder.com/practice/de044e89123f4a7482bd2b214a685201
round = int(input()) #输入数据的次数
while True:
try:
dict={} #创建字典接收数据
for i in range(round):
data = input().split(' ')
index = int(data[0]) #获取索引
qty = int(data[1]) #获取值
dict[index] = dict.get(index, 0)+qty #若索引不在字典内,直接添加; 若存在,累加
for i in sorted(dict.keys()): #按顺序索引输出
print('{0} {1}'.format(i, dict[i]))
except:
break
