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