题解 | #记负均正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; }