2021级《程序设计原理及C语言》练习题

L. grade

单点时限: 2.0 sec

内存限制: 512 MB

Finish the definition of the following function which computes the grades of $n$ students for a course given their scores.

#include <stdio.h>
void grade(int score[], int n, char grade[])
/*
Precondition:
score[]: the scores (0-100) of n (n>0) students
Postcondition:
Compute the grade ('A': 90-100; 'B': 80-89; 'C': 70-79; 'D': 60-69; 'F': 0-59)
of each student, and store the result in grade[] in the same order as in
score[]. Display the distributions of the grades including the total number
(field with=4) and the percentage (field width=8) of each grade in the following
format:
A:  30  30.00%
B:  20  20.00%
C:  20  20.00%
D:  20  20.00%
F:  10  10.00%
*/
{
    // your definition here
}

#define MAXN 100

int main()
{
    int n;
    scanf("%d", &n);
    int score[MAXN];
    char g[MAXN];
    for (int i = 0; i < n; i++) 
        scanf("%d", &score[i]);
    grade(score, n, g);
}

样例

Input
10
50 60 65 70 75 80 85 90 95 100
Output
A:   3   30.00%
B:   2   20.00%
C:   2   20.00%
D:   2   20.00%
F:   1   10.00%