题解 | #合并表记录#

合并表记录

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

#先生成字典保存键值对
#对字典的键的列表排序,按顺序输出即可
import sys
while True:
    try:
        n = int(input())
        dic = {}
        for i in range(n):
            key, value = map(int, input().split())
            if key in dic:
                dic[key] += value
            else:
                dic[key] = value
        l = sorted(list(dic.keys()))
        for c in l:
            print(c, dic[c])
    except:
#         print(sys.exc_info())
        break


















全部评论

相关推荐

评论
点赞
收藏
分享

创作者周榜

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