题目链接:记负均正_牛客题霸_牛客网
注意点:
注意
1.for循环 ,i是从1开始
2.小数点后1位的保存
#include <iostream>
#include <iomanip>
using namespace std;
int main(){
int n;
while (cin >> n){
int sum = 0;
//大于0的个数
int cnt = 0;
//小于0的个数
int num = 0;
for (int i = 1; i <= n; ++i){
int tmp;
cin >> tmp;
if(tmp > 0) {
sum += tmp;
++cnt;
}
else if (tmp < 0 )
{
num++;
}
}
cout << num << " "<< fixed << setprecision(1) << (sum * 1.0 / cnt) << "\n";
}
return 0;
}