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