hdu2023-第一个

来源:互联网 发布:java https post请求 编辑:程序博客网 时间:2024/06/14 17:52

做的第一个题目,很简单,但是历经了18次提交,终于accept,OJ要求很高, 中间出现各种wrong answer/presentation error, answer ,所以记录一下,虽然开始的有点晚,better late than never, 继续努力~


Problem Description
假设一个班有n(n<=50)个学生,每人考m(m<=5)门课,求每个学生的平均成绩和每门课的平均成绩,并输出各科成绩均大于等于平均成绩的学生数量。

Input
输入数据有多个测试实例,每个测试实例的第一行包括两个整数n和m,分别表示学生数和课程数。然后是n行数据,每行包括m个整数(即:考试分数)。

Output
对于每个测试实例,输出3行数据,第一行包含n个数据,表示n个学生的平均成绩,结果保留两位小数;第二行包含m个数据,表示m门课的平均成绩,结果保留两位小数;第三行是一个整数,表示该班级中各科成绩均大于等于平均成绩的学生数量。
每个测试实例后面跟一个空行。
Sample Input
2 2
5 10
10 20

Sample Output
7.50 15.00
7.50 15.00
1


代码:

#include<iostream>#include "iomanip"#include<math.h>using namespace std;int main() {    int a[50][5];    int i, j;    int m, n;    while (cin>>m>>n)    {        double aver_stu[50] = { 0.0 };        double aver_cour[5] = { 0.0 };        int count = 0;        for (i = 0; i < m; i++)            for (j = 0; j < n; j++)            {            cin >> a[i][j];            aver_stu[i] +=  a[i][j];            aver_cour[j] += a[i][j];            }        for ( i = 0; i < m; i++)        {            aver_stu[i] = aver_stu[i] / n;        }        for ( i = 0; i <m ; i++)        {            cout << setprecision(2) << std::fixed << aver_stu[i]<<" ";        }        cout << endl;        for ( j = 0; j < n; j++)        {            aver_cour[j] = aver_cour[j] / m;        }        for ( j = 0; j < n; j++)        {            cout << setprecision(2) << std::fixed << aver_cour[j]<<" ";        }        cout << endl;        for (i = 0; i < m; i++)        {            bool flag = true;            for (j = 0; j < n; j++)            {                if (a[i][j] < aver_cour[j])                {                    flag = false;                    break;                }            }            if (flag)            {                count++;            }        }        cout << count << endl << endl;    }    return 0;}----------遇到的错误:1 VS++平台的标准头#include "stdafx.h"在OJ上无法找到,直接Compilation Error2 输出格式 中间间隔加" ",每个实例间空一行;
0 0