题解 | #合并表记录#

合并表记录

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

# 用字典哈希相同覆盖原来的, 新的值从老的字典中get后相加
total = input()
total_dic = {}
for i in range(int(total)):
    k_v = input().split()
    k = int(k_v[0])
    v = int(k_v[1])
    total_dic[k] = total_dic.get(k,0) + v
for t_d in sorted(total_dic):
    print(t_d, total_dic[t_d])

全部评论

相关推荐

真烦好烦真烦:牛友太有实力了
点赞 评论 收藏
分享
缒梦&独舞:这家公司是这样的,去年给我实习offer了,不过也是面着玩儿的,他周六还要去做公益志愿活动
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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