题解 | #合并表记录#

合并表记录

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

a = int(input())
dic = {}
for i in range(a):
    tem = input().split( )
    index = int(tem[0])
    value = int(tem[1])
    if index in dic:##直接判断引索字符串在不在字典里
        dic[index] = dic[index] + value
    else:
        dic[index] = value
# print(sorted(dic.items()))     [(0, 3), (1, 2), (3, 4)]#sorted帮你转变成列表
# print(type((dic.items())))      <class 'dict_items'>
# print(dic.items())                  dict_items([(0, 3), (1, 2), (3, 4)])
for w in sorted(dic.items()):
    print(w[0],w[1])

【牛客站内】华为机试题练习记录

全部评论

相关推荐

强大的马里奥:不太可能,我校计算机硕士就业率99%
点赞 评论 收藏
分享
买蜜雪也用卷:我觉得应该没有哪个人敢说自己熟练使用git,代码分支一复杂还是得慢慢寻思一下的,不过基本的拉代码提交代码还有分支什么的是应该会
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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