其他分享
首页 > 其他分享> > 杭电2023 求平均成绩

杭电2023 求平均成绩

作者:互联网

C

#include <stdio.h>

int main()
{
    int n, m;
    while (scanf("%d %d", &n, &m) != EOF) {
        double s[n][m];
        for (int i = 0; i < n; ++i) {
            for (int j = 0; j < m; ++j) {
                scanf("%lf", &s[i][j]);
            }
        }
        for (int i = 0; i < n; ++i) {
            double sum = 0;
            for (int j = 0; j < m; ++j) {
                sum += s[i][j];
            }
            if (!i) printf("%.2lf", sum / m);
            else printf(" %.2lf", sum / m);
        }
        printf("\n");
        double e[m];
        for (int i = 0; i < m; ++i) {
            double sum = 0;
            for (int j = 0; j < n; ++j) {
                sum += s[j][i];
            }
            e[i] = sum / n;
            if (!i) printf("%.2lf", e[i]);
            else printf(" %.2lf", e[i]);
        }
        printf("\n");
        int people = 0;
        for (int i = 0; i < n; ++i) {
            int flag = 1;
            for (int j = 0; j < m; ++j) {
                if (s[i][j] < e[j]) flag = 0;
            }
            if (flag) people += 1;
        }
        printf("%d\n\n", people);
    }
    return 0;
}

标签:2lf,int,double,sum,2023,杭电,++,printf,成绩
来源: https://blog.csdn.net/Justodiante/article/details/113575223