题解 | #记负均正#
记负均正
https://www.nowcoder.com/practice/6abde6ffcc354ea1a8333836bd6876b8
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 while(line = await readline()){ let n = parseInt(line); let str_num = await readline(); let arr_num = str_num.split(' '); let positive_count = 0, negative_count = 0; // 正数的个数和负数的个数 let positive_sum = 0; for(let i=0; i<arr_num.length; i++){ let tmp = parseInt(arr_num[i]); if(tmp>0){ positive_count++; positive_sum+=tmp }else if(tmp<0){ negative_count++; } } let res = ''; if(positive_count==0){ res = '0.0'; // 注意这里是0.0 }else{ res = parseFloat(positive_sum/positive_count).toFixed(1) } console.log(negative_count+' '+res); } }()