题解 | #记负均正II#

记负均正II

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

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 num = 0;
    let sum = 0;
    let n = 0;
    let average = 0;
    while(line = await readline()){
        let number = parseInt(line);
        if(number<0) num++;
        else {
            sum+=number;
            n++;
        }
    }
    if(n===0)average=0;
    else average=sum/n;
    console.log(num);
    console.log(average.toFixed(1));
}()

全部评论

相关推荐

10-06 12:46
门头沟学院 Java
跨考小白:定时任务启动
点赞 评论 收藏
分享
点赞 评论 收藏
分享
点赞 收藏 评论
分享
牛客网
牛客企业服务