题解 | #记负均正#
记负均正
https://www.nowcoder.com/practice/6abde6ffcc354ea1a8333836bd6876b8
#define _CRT_SECURE_NO_WARNINGS #include <stdio.h> int main() { int n = 0; int arr[3000] = { 0 }; while (scanf("%d", &n) != EOF) { int i = 0; for (i = 0; i < n; i++) { scanf("%d", &arr[i]); } int neg = 0; int pos = 0; int count = 0; double average = 0; for (i = 0; i < n; i++) { if (arr[i] < 0) { neg++; } else if (arr[i] > 0) { pos++; count += arr[i]; } } if (pos!=0) average = (double)count / pos; printf("%d %.1lf\n", neg, average); } return 0; }