题解 | #记负均正II#

记负均正II

https://www.nowcoder.com/practice/64f6f222499c4c94b338e588592b6a62

const readline = require('readline');

const rl = readline.createInterface({
    input: process.stdin,
    output: process.stdout
});

const lines: number[] = [];

rl.on('line', function (line) {
    lines.push(parseInt(line));
});

rl.on('close', () => {
    let negativeCount = 0;
    let notNegativeTotal = 0;
    lines.forEach((item) => {
        if (item < 0) {
            negativeCount++;
        } else {
            notNegativeTotal += item;
        }
    })
    console.log(negativeCount);
    const ave = notNegativeTotal ? (notNegativeTotal / (lines.length - negativeCount)) : 0;
    console.log(ave.toFixed(1));
})

全部评论

相关推荐

评论
点赞
收藏
分享

创作者周榜

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