题解 | #合并表记录#
合并表记录
http://www.nowcoder.com/practice/de044e89123f4a7482bd2b214a685201
let arr = []
while(line = readline()) {
arr.push(line);
}
const length = arr[0];
let list = arr.slice(1, length + 1);
let newArr = [];
for (item of list) {
let key = parseInt(item.split(' ')[0]);
let value = parseInt(item.split(' ')[1]);
newArr[key] = newArr[key] ? newArr[key] + value : value;
}
for (key in newArr) {
if (newArr[key]) {
print(key + ' ' + newArr[key]);
}
}