题解 | #合并表记录#
合并表记录
http://www.nowcoder.com/practice/de044e89123f4a7482bd2b214a685201
n = int(input()) dict1 ={} for i in range(n): index,value = input().split() index=int(index) value=int(value) # 居然还要判断边界 if 0<=index<=11111111 and 1<=value<=100000: if dict1.get(index): dict1[index]=value + dict1[index] else: dict1[index] = value #print(dict1)
居然要排序,排序注意,我开始index存的是str,导致排序1,11,2这种问题,后来改成int才通过
sort_dict = sorted(dict1.keys()) for i in sort_dict: print(i,dict1[i])