题解 | #记负均正II#

记负均正II

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

#include <bits/stdc++.h>
using namespace std;

int main() {
    float num = 0;
    int c1 = 0;
    int c2 = 0;
    float sum = 0.0;
    float avg = 0.0;
    while (cin >> num) {
        if (num < 0) {
            ++ c2;
        } else if (num > 0) {
            ++ c1;
            sum += num;
            avg = sum / c1;
        }
    }
    cout << c2 << endl;
    cout << setiosflags(ios::fixed|ios::showpoint) << setprecision(1) << avg << endl;
}

全部评论

相关推荐

点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客企业服务