题解 | #合并表记录#
合并表记录
http://www.nowcoder.com/practice/de044e89123f4a7482bd2b214a685201
hash_tab = {}
while True:
try:
num_list = input().split(' ')
except:
break
if len(num_list) == 1:
...
else:
key = int(num_list[0])
value = int(num_list[1])
if hash_tab.get(key):
hash_tab[key] += value
else:
hash_tab[key] = value
keys = sorted(hash_tab) # 注意题目描述,升序排列键值
for key in keys:
print(key, hash_tab[key])