题解 | #记负均正#
记负均正
https://www.nowcoder.com/practice/6abde6ffcc354ea1a8333836bd6876b8
// HJ97-2 记负均正.cpp : 此文件包含 "main" 函数。程序执行将在此处开始并结束。 #include<iostream> #include<bits/stdc++.h> using namespace std; int main() { int n; while (cin >> n) { int ans = 0,sum=0,num=0; for (int i = 0; i < n; i++) { int x; cin >> x; if (x < 0) { ans++; } else if (x > 0) { sum += x; num++; } } double a = sum,b=num; cout << ans << " "; if (sum == 0) { cout << "0.0" << endl; } else { cout << setprecision(1) << fixed << a/b << endl; } } return 0; }