杭电 征程 2000-2099 题中的简单小结 written by English
http://acm.hdu.edu.cn/showproblem.php?pid=2023
求平均成绩
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 34271 Accepted Submission(s): 8131
Problem Description
假设一个班有n(n<=50)个学生,每人考m(m<=5)门课,求每个学生的平均成绩和每门课的平均成绩,并输出各科成绩均大于等于平均成绩的学生数量。
Input
输入数据有多个测试实例,每个测试实例的第一行包括两个整数n和m,分别表示学生数和课程数。然后是n行数据,每行包括m个整数(即:考试分数)。
Output
对于每个测试实例,输出3行数据,第一行包含n个数据,表示n个学生的平均成绩,结果保留两位小数;第二行包含m个数据,表示m门课的平均成绩,结果保留两位小数;第三行是一个整数,表示该班级中各科成绩均大于等于平均成绩的学生数量。
(每个测试实例后面跟一个空行)<-this place need to pay more attention~~ and you need to konw that you need to use 'double' to caluate average score this can avoid the wrong answer.
(每个测试实例后面跟一个空行)<-this place need to pay more attention~~ and you need to konw that you need to use 'double' to caluate average score this can avoid the wrong answer.
Sample Input
2 2
5 10
10 20
Sample Output
7.50 15.00
7.50 15.00
1
#include<stdio.h> #include<string.h> int main() { double a[52][5],b[6],stu[52],sum=0; //use double to make average score more precious which can avoid wrong answer. int n,m,row,line,i,j,num1,num; while(scanf("%d %d",&n,&m)!=EOF){ memset(a,0,sizeof(a)); memset(b,0,sizeof(b)); memset(stu,0,sizeof(stu)); num=0; row=n; line=m; for(j=1;j<=n;j++) for(i=1;i<=m;i++) {scanf("%lf",&a[j][i]);stu[j]+=a[j][i];} for(i=1;i<=m;i++) { sum=0; for(j=1;j<=n;j++) sum+=a[j][i]; b[i]=sum/n; } for(i=1;i<=n;i++) {num1=0; for(j=1;j<=m;j++) if(b[j]<=a[i][j]){num1++;/*printf("num1=%d ",num1);*/} if(num1==m)num++; //printf("num=%d\n"); } for(j=1;j<=n;j++) {printf("%.2lf",stu[j]/m);if(j!=n)printf(" ");} printf("\n"); for(i=1;i<=m;i++) {printf("%.2lf",b[i]);if(i!=m)printf(" "); } printf("\n"); printf("%d\n",num); printf("\n"); //pay more attention to the output .after each case there exist a space there. } }