题解 | #记负均正#
记负均正
http://www.nowcoder.com/practice/6abde6ffcc354ea1a8333836bd6876b8
#include<stdio.h>
int main() { int n = 0;
while (scanf("%d", &n) != EOF)
{
int cnt = 0;//记录负数的个数
int ret = 0;//记录正数的个数
double sum = 0.0;//存放正数和
int tmp = 0;
int i = 0;
for (i = 0; i < n; i++)
{
scanf("%d", &tmp);
if (tmp < 0)
{
cnt++;
}
else if(tmp > 0)
{
sum += tmp;
ret++;
}
}
if (ret == 0)
{
printf("%d 0.0\n", cnt);
}
else
{
printf("%d %.1lf\n", cnt, sum / ret);
}
}
return 0;
}