题解 | #合并表记录#

合并表记录

https://www.nowcoder.com/practice/de044e89123f4a7482bd2b214a685201

const rl = require("readline").createInterface({ input: process.stdin });
var iter = rl[Symbol.asyncIterator]();
const readline = async () => (await iter.next()).value;

void (async function () {
  // Write your code here
  let arr = []
  while ((line = await readline())) {
    let newstr = line.split(" ");
    if (newstr[1]) {
      let num = parseInt(newstr[0]);
      let num1 = parseInt(newstr[1]);
      if (arr[num]) {
          arr[num] += num1
      } else {
          arr[num] = num1
      }
    }
  }
    arr.forEach((item, index) => {
      console.log(index, item);
    });
})();

#华为机考#
全部评论

相关推荐

评论
2
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务