题解 | #记负均正II#
记负均正II
https://www.nowcoder.com/practice/64f6f222499c4c94b338e588592b6a62
#include <stdio.h> int main() { int input; float positiveNumAverage = 0; int negativeCount = 0; int positiveNumCount = 0; int positiveNumTotal = 0; while (scanf("%d", &input) != EOF) { //就这一句读入 if (input < 0) { negativeCount++; } if (input > 0) { positiveNumTotal += input; positiveNumCount++; } } if (positiveNumTotal != 0) { positiveNumAverage = (float)positiveNumTotal / positiveNumCount; //记得faloat转换数据类型 } printf("%d\n%.1f\n", negativeCount, positiveNumAverage); return 0; }