题解 | #记负均正#
记负均正
https://www.nowcoder.com/practice/6abde6ffcc354ea1a8333836bd6876b8
// HJ97 记负均正.cpp : 此文件包含 "main" 函数。程序执行将在此处开始并结束。
//
#include<iostream>
#include<bits/stdc++.h>
#include<cstdio>
using namespace std;
int main()
{
int n;
while (cin >> n)
{
int count = 0;
int sum = 0,res=0;
vector<int>dp(n);
for (int i = 0; i < n; i++)
{
cin >> dp[i];
}
for (int j = 0; j < dp.size(); j++)
{
if (dp[j] < 0)
{
count++;
}
if (dp[j] > 0)
{
res++;
sum += dp[j];
}
}
cout << count << " ";
double num,a=sum,b=res;
if (res != 0)
{
num = a / b;
cout << setprecision(1) <<fixed<< num << endl;//保留1位小数
//printf("%.1f", num);
}
else
{
cout << "0.0" << endl;
}
}
return 0;
}