3367 - 统计

通过次数

0

提交次数

0

时间限制 : 1 秒 内存限制 : 128 MB

读一组实数,遇零终止,打印其中正、负数的个数及各数的总和

题目输入

输入只有一行,为若干个[-106,106]实数,输入的最后一个数肯定是0,且除了最后一位,中间不会出现0,不存在没有输入的情况。(保证输入的个数不大于10000个)

题目输出

输出只有一行,为三个实数分别为正数的个数、负数的个数和所有数之和。(实数结果保留三位小数)

输入/输出样例

输入格式

-1 -2 3 5 0

输出格式

2 2 5.000

C++解答

#include <cstdlib>
#include <cstdio>
using namespace std;
int main()
{
	double lf_input;
	double sum=0;
	scanf("%lf",&lf_input);
	long long int d_zs=0,d_fs=0;
	while(lf_input!=0)
	{
		sum+=lf_input;
		if(lf_input<0)
		    d_fs++;
		if(lf_input>0)
		    d_zs++;
        scanf("%lf",&lf_input);
	}
	printf("%lld %lld %.3lf",d_zs,d_fs,sum);
	//system("pause");
	return 0;
}