3367 - 统计
读一组实数,遇零终止,打印其中正、负数的个数及各数的总和
Input
输入只有一行,为若干个[-106,106]实数,输入的最后一个数肯定是0,且除了最后一位,中间不会出现0,不存在没有输入的情况。(保证输入的个数不大于10000个)
Output
输出只有一行,为三个实数分别为正数的个数、负数的个数和所有数之和。(实数结果保留三位小数)
Examples
Input
-1 -2 3 5 0
Output
2 2 5.000
Hint
题目来源:吕红波
Solution 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; }
Hint
题目来源:吕红波