题解 | #记负均正#

记负均正

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;
}

全部评论

相关推荐

选钝角的小学生很热爱...:佬,今天收到的嘛?我三面结束二十天了,没人联系😅。请问你base哪里啊
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务