题解 | #合并表记录#
合并表记录
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