题解 | #合并表记录#

合并表记录

https://www.nowcoder.com/practice/de044e89123f4a7482bd2b214a685201

import sys

n = int(input())

l = list()	#用list(tuple,tuple)存储
res = dict()	#用dic存index
for i in range(n):
    index, value = input().split(' ')
    l.append((int(index), int(value)))
    res[int(index)] = 0

# 更新dic的value
for item in l:
    res[item[0]] = res[item[0]] + item[1]
	
# 根据字典的key排序
res = dict(sorted(res.items(), key=lambda x: x[0]))

for key, value in res.items():
    print(key, value)

全部评论

相关推荐

瑞雪兆丰年_:可以贴个超级大的校徽,以防HR眼拙
点赞 评论 收藏
分享
评论
点赞
1
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务