题解 | #记负均正#

记负均正

http://www.nowcoder.com/practice/6abde6ffcc354ea1a8333836bd6876b8

let arr = []
while(line = readline()) {
    arr.push(line);
}

let newArr = [];
newArr.push(arr.slice(0, 2));
newArr.push(arr.slice(2));

for (let item of newArr) {
    const n = parseInt(item[0]);
    const listArr = item[1].split(' ').map((num) => parseInt(num));
  // 负数个数
    let total =  listArr.filter((num) => num < 0).length;
    let count = 0;
  //正数数组
    let zhengshu = listArr.filter((num) => num > 0);
    for (let i of zhengshu) {
        count += i;
    }
    let result = [total, (count/zhengshu.length).toFixed(1)];
    print(result.join(' '));
    
}
全部评论

相关推荐

10-14 13:25
已编辑
门头沟学院 C++
点赞 评论 收藏
分享
点赞 收藏 评论
分享
牛客网
牛客企业服务