先输入键值对的个数 然后输入成对的index和value值,以空格隔开 输出描述: 输出合并后的键值对(多行)
合并表记录
http://www.nowcoder.com/questionTerminal/de044e89123f4a7482bd2b214a685201
while True:
try:
n = int(input())
a = []
for i in range(n):
a.append(list(map(int,input().split())))
b = []
for i in a:
b.append(i[0])
c = []
for i in sorted(list(set(b))):
value = 0
for j in a:
if i == j[0]:
value+=j[1]
c.append([str(i),str(value)])
print(' '.join([str(i),str(value)]))
except:
break