AcWing 791. 高精度加法
原题链接
简单
作者:
一个不正经的程序员
,
2024-11-21 12:05:32
,
所有人可见
,
阅读 1
// 高精度算法
const readline = require('readline').createInterface({
input: process.stdin,
output: process.stdout
})
const input = []
readline.on('line', (line) => {
input.push(line)
})
let flag = 0;
let res = []
readline.on('close',()=> {
const arr1 = input[0].split('').map(v=> Number(v));
const arr2 = input[1].split('').map(v=> Number(v));
while (arr1.length > 0 || arr2.length > 0) {
const num1 = arr1.pop() || 0
const num2 = arr2.pop() || 0
const tem = num2 + num1+ flag;
res.unshift( tem % 10)
flag = Math.floor(tem / 10)
}
if(flag) res.unshift(flag);
console.log(res.join(''));
})