题解 | #记负均正II#
记负均正II
https://www.nowcoder.com/practice/64f6f222499c4c94b338e588592b6a62
#include <stdio.h>
int main()
{
int n=0;
int count1=0;
int count2=0;
double sum=0;
while(scanf("%d",&n) != EOF)
{
if(n < 0)
count2++;
else
{
sum += n;
count1++;
}
}
double ave =(sum/count1)>0?(sum/count1):0;
printf("%d\n%0.1lf\n",count2,ave);
return 0;
}
int main()
{
int n=0;
int count1=0;
int count2=0;
double sum=0;
while(scanf("%d",&n) != EOF)
{
if(n < 0)
count2++;
else
{
sum += n;
count1++;
}
}
double ave =(sum/count1)>0?(sum/count1):0;
printf("%d\n%0.1lf\n",count2,ave);
return 0;
}