题解 | #记负均正II#

记负均正II

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

#include <ios>
#include <iostream>
using namespace std;
#include <iomanip>

int main() {
    double res = 0.0;
    int cntP = 0;
    int cnt = 0;
    int a;
    while(cin >> a){
        if(a > 0){
            res += a;
            cntP++;
        }else{
            cnt++;
        }
    }
    if(cntP!=0){
        res = res/cntP;
    }
    
    cout << cnt << endl;
    cout <<setprecision(1)<<fixed <<res << endl;
}
// 64 位输出请用 printf("%lld")

要注意计数为0的情况和一位小数输出

fixed的加入才会输出0.0

全部评论

相关推荐

05-09 12:10
济宁学院 Java
程序员小白条:丰富下简历,有点少了,中小厂反正看运气海投
点赞 评论 收藏
分享
夏目LTH:这个真的很看运气,多投吧。我从去年十二月底一直投到现在,之前没一个offer,结果两周前投的一家面试官聊的特别好,直接速通offer还给的SP待遇开的比我期望都够。
我的求职进度条
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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