参考代码如下:
#include <stdio.h> #include <string.h> void printarr(int *a, int len) { int i, j; for (i = 0; i < len - 1; i++) { for (j = i + 1; j < len; j++) { if (a[i] < a[j]) { int tmp = a[i]; a[i] = a[j]; a[j] = tmp; } } } for (i = 0; i < len; i++) { printf("%d ", a[i]); } printf("\n"); } int main(void) { int n; scanf("%d", &n); int A[n]; int B[n]; int C[n]; int D[n]; int E[n]; int aidx = 0; int bidx = 0; int cidx = 0; int didx = 0; int eidx = 0; int score; int i; for (i = 0; i < n; i++) { scanf("%d", &score); if (score <= 100 && score >= 90) { A[aidx++] = score; } if (score <= 89 && score >= 80) { B[bidx++] = score; } if (score <= 79 && score >= 70) { C[cidx++] = score; } if (score <= 69 && score >= 60) { D[didx++] = score; } if (score <= 59 && score >= 0) { E[eidx++] = score; } } printf("%d %d %d %d %d\n", aidx, bidx, cidx, didx, eidx); int arr[5] = {aidx, bidx, cidx, didx, eidx}; int max = 0; int maxidx = 0; for (i = 0; i < 5; i++) { if (max < arr[i]) { max = arr[i]; maxidx = i; } } printf("%d\n", arr[maxidx]); if (maxidx == 0) printarr(A, aidx); else if (maxidx == 1) printarr(B, bidx); else if (maxidx == 2) printarr(C, cidx); else if (maxidx == 3) printarr(D, didx); else if (maxidx == 4) printarr(E, eidx); return 0; }
0.0分
0 人评分