码迷,mamicode.com
首页 > 其他好文 > 详细

求平均成绩(hdu2023)

时间:2016-10-23 07:50:16      阅读:167      评论:0      收藏:0      [点我收藏+]

标签:pre   alt   错误   char   1.0   技术分享   ble   #include   std   

技术分享

注意:要心细,不要错在小细节上。如int c[6];double agve; c[j]=agve;这是错误的。

#include<stdio.h>
#include<cmath>
int a[51][6];
double c[6];
int main()
{
    int n;
    int m;
    char d;
    while (scanf_s("%d%d%c", &n, &m, &d) != EOF)
    {
        for (int i = 0; i<n; i++)
        {
            for (int j = 0; j<m; j++)
            {
                int b;
                scanf_s("%d", &b);
                a[i][j] = b;
            }
        }
        for (int i = 0; i<n; i++)
        {
            double sum = 0;
            double avge;
            for (int j = 0; j<m; j++)
            {
                sum = sum + a[i][j];
            }
            avge = sum*1.0 / m;
            printf("%0.2lf", avge);
            if (i<n - 1)
                printf(" ");
        }
        printf("\n");
        for (int j = 0; j<m; j++)
        {
            double sum = 0;
            double avge;
            for (int i = 0; i<n; i++)
            {
                sum = sum + a[i][j];
            }
            avge = sum*1.0 / n;
            c[j] = avge;
            printf("%0.2lf", avge);
            if (j<m - 1)
                printf(" ");
        }
        printf("\n");
        int count = 0;
        for (int i = 0; i<n; i++)
        {
            int count1 = 0;
            for (int j = 0; j<m; j++)
            {
                if (a[i][j] >= c[j])
                    count1++;
            }
            if (count1 == m)
                count++;
        }
        printf("%d\n\n", count);
    }
}

 

求平均成绩(hdu2023)

标签:pre   alt   错误   char   1.0   技术分享   ble   #include   std   

原文地址:http://www.cnblogs.com/Strugglinggirl/p/5988950.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!