发布网友 发布时间:2022-04-24 13:56
共1个回答
热心网友 时间:2023-10-15 08:48
//*******************************************************************
// 杭电2023 求平均成绩 代码已AC
// n(n<=50)个学生,每人考m(m<=5)门课
// 注意这个循环 for(i = 1; i <= n; i++)
// 已经使用到 n 所以数组a 应该设置大一点,即 a[51][6]
// 另外一个问题就是 每次循环后count1 没有重新置零
//*******************************************************************
#include <stdio.h>
int main()
{
int n, m, i, j, count1, count2;
double a[51][6]; //后面程序访问到 n 所以应该定义为a[51][6]
while(scanf("%d%d", &n, &m) != EOF)
{
count1 = count2 = 0;
for(i = 0; i <= n; i++)
for(j = 0; j <= m; j++)
a[i][j] = 0;
for(i = 1; i <= n; i++)
for(j = 1; j <= m; j++)
scanf("%lf", &a[i][j]);
for(i = 1; i <= n; i++)
{
for(j = 1; j <= m; j++)
a[i][0] = a[i][0] + a[i][j];
a[i][0] = a[i][0] / m;
}
for(i = 1; i <= m; i++)
{
for(j = 1; j <= n; j++)
a[0][i] = a[0][i] + a[j][i];
a[0][i] = a[0][i] / n;
}
for(i = 1; i < n; i++)
printf("%.2lf ", a[i][0]);
printf("%.2lf\n", a[n][0]);
for(j = 1; j < m; j++)
printf("%.2lf ", a[0][j]);
printf("%.2lf\n", a[0][m]);
for(i = 1; i <= n; i++) //**************************
{
count1=0; //添加这一句
for(j = 1; j <= m; j++) //每次循环后count1应该重新置零
{
if(a[i][j] >= a[0][j])
count1 = count1 + 1;
}
if(count1 == m)
count2 = count2 + 1;
} //**************************
printf("%d\n", count2);
printf("\n");
}
}
//*******************************************************************
// 祝学习进步,更上一层楼 *(^-^)*
//*******************************************************************