题解 | #合并表记录#

合并表记录

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

def my_func(data):
    res = dict()
    pairs = data[1:]
    for i in pairs:
        ind, ind_value = i.split(" ")
        if ind not in res:
            res[ind] = ind_value
        else:
            res[ind] = str(int(res[ind]) + int(ind_value))
    temp = sorted(res.items(), key=lambda x :int(x[0]), reverse=False)
    for key, value in temp:
        print(f"{key} {value}")













data = []
while True:
    try:
        data.append(input())
    except (EOFError, KeyboardInterrupt):
        break


my_func(data)
全部评论

相关推荐

买蜜雪也用卷:我觉得应该没有哪个人敢说自己熟练使用git,代码分支一复杂还是得慢慢寻思一下的,不过基本的拉代码提交代码还有分支什么的是应该会
点赞 评论 收藏
分享
头顶尖尖的程序员:我也是面了三四次才放平心态的。准备好自我介绍,不一定要背熟,可以记事本写下来读。全程控制语速,所有问题都先思考几秒,不要急着答,不要打断面试官说话。
点赞 评论 收藏
分享
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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