题解 | #记负均正II#
记负均正II
https://www.nowcoder.com/practice/64f6f222499c4c94b338e588592b6a62
#include <iomanip> #include <iostream> using namespace std; int main() { int a; int cnt = 0; int zhengshu_cnt = 0; double sum = 0; while (cin >> a) { if (a < 0) { cnt += 1; } else if (a > 0) { sum += a; zhengshu_cnt += 1; } } if (zhengshu_cnt == 0) { cout << cnt << endl << fixed << setprecision(1) << 0.0 << endl; } else { cout << cnt << endl << fixed << setprecision(1) << (sum / zhengshu_cnt) << endl; } } // 64 位输出请用 printf("%lld")