Problem : 2023 ( 求平均成绩 )

发布时间:2020-01-13 13:06:16 作者:ranyue 阅读量:111

Problem Description
假设一个班有n(n<=50)个学生,每人考m(m<=5)门课,求每个学生的平均成绩和每门课的平均成绩,并输出各科成绩均大于等于平均成绩的学生数量。
#include<bits/stdc++.h>
using namespace std;

struct student
{
int class_score[10];

}students;

struct table
{
double indiv_argv_score[50];
double class_argv_score[10];
int cout;

};

int main()
{
int m, n;
struct student s[100];
struct table t;
bool flag = false;
while (cin >> n >> m)
{
if (n == 0)break;
double indiv_sum_sorce = 0;
double class_sum_sorce = 0;
for (int i = 0; i <n; i++)
{
for (int j = 0; j < m; j++)
{
cin >> s[i].class_score[j];
}
}

//计算个人的平均成绩
for (int i = 0; i < n; i++)
{
indiv_sum_sorce = 0;
for (int j = 0; j < m; j++)
{
indiv_sum_sorce += s[i].class_score[j];
}
t.indiv_argv_score[i] = indiv_sum_sorce / m;
}

//计算每科的平均成绩
for (int j = 0; j < m; j++)
{
class_sum_sorce = 0;
for (int i = 0; i < n; i++)
{
class_sum_sorce += s[i].class_score[j];
}
t.class_argv_score[j] = class_sum_sorce / n;
}

//计算人数
t.cout = 0;
for (int i = 0; i < n; i++)
{
for (int j = 0; j < m; j++)
{
if (s[i].class_score[j] >= t.class_argv_score[j])
{
flag = true;
}
else
{
flag = false;
}
}
if (flag)
{
t.cout++;
}

}

//输出每个人的平均成绩
int s = 0;
for (int s = 0; s < n - 1; s++)
{
cout << fixed << setprecision(2);
cout << t.indiv_argv_score[s] << " ";
}
cout << t.indiv_argv_score[s + 1] << endl;

//输出各科的平均成绩
int a = 0;
for (int a = 0; a < m - 1; a++)
{
cout << t.class_argv_score[a] << " ";
}
cout << t.class_argv_score[a + 1] << endl;
//输出人数
cout << t.cout<<endl;
cout << endl;


}


return 0;


}

上一篇:

我要评论 登录后才能发布评论

复试练习

ranyue(染月)   我要留言
Catfish(鲶鱼) CMS V 5.9.15