#include <iostream>
#include<iomanip>
#include<vector>
#include<algorithm>
#include<cmath>
using namespace std;
int main()
{
int n, m;
while (cin >> n >> m)
{
double a[55][6];
double b[55];
double c[6];
for (int i = 0; i < n; i++)//录入学生成绩
{
for (int j = 0; j < m; j++)
{
cin >> a[i][j];
}
}
for (int i = 0; i < n; i++)//求学生每个的平均成绩
{
double sum = 0;//这边的sum我一开始是用的int,导致后面计算平均值全都没有小数,找了半天错呜呜呜
for (int j = 0; j < m; j++)
{
sum = sum + a[i][j];
}
b[i] = sum / m;
}
for (int i = 0; i < m; i++)//每个学科的平均成绩
{
double sum = 0;
for (int j = 0; j < n; j++)
{
sum = sum + a[j][i];
}
c[i] = sum / n;
}
int count = 0;
for (int i = 0; i < n; i++)
{
int t = 1;
for (int j = 0; j < m; j++)
{
if (a[i][j] < c[j])
t = 0;
}
if (t == 1)
count++;
}
for (int i = 0; i < n-1; i++)
{
cout << fixed << setprecision(2) << b[i]<<" ";
}
cout << fixed << setprecision(2) << b[n - 1] << endl;
for (int i = 0; i < m-1; i++)
{
cout << fixed << setprecision(2) << c[i] << " ";
}
cout<< fixed << setprecision(2) << c[m - 1] << endl;
cout << count << endl;
cout << endl;//这里很重要,每个实例后面还要多一行,没注意的话就会pe;
}
return 0;
}
小熊崽纸的2023
最新推荐文章于 2020-07-30 15:08:08 发布