题解 | 合并表记录

合并表记录

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

import sys
n = int(input())
dict1 = {}
for i in range(n):
    x,y = map(int,sys.stdin.readline().strip().split())
    if x not in dict1:
        dict1[x] = y
    else:
        dict1[x] += y
sorted_key = sorted(dict1.keys())
for x in sorted_key:
    print(x,dict1[x])



# n = int(sys.stdin.readline())
# d = {}
# for i in range(n):
#     x,y = map(int,sys.stdin.readline().split())
#     if x in d:
#         d[x] += y
#     else:
#         d[x] = y
# sorted_key = sorted(d.keys())
# for k in sorted_key:
#     print(k,d[k])

全部评论

相关推荐

程序员小白条:vibe你只要能cover住面试官问你很多深入的实现和选型方案的原因,以及怎么去检测优化效果的就行了
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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