HDU 1202 The calculation of GPA
来源:互联网 发布:热力学数据计算软件 编辑:程序博客网 时间:2024/05/19 02:01
/*
题目大意:求平均数
解题思路:按照题目要求即可
关键点:注意细节
解题人:lingnichong
解题时间:2014-08-12 21:24:06
解题体会:题目思路比较简单,代码也比较好写。就是注意一些细节就好,个人感觉题目有点坑,要将程序中间将p改成整型
*/
写错了,还在改进中 2014-08-12 15:12:31...现在改过来了
#include<stdio.h>int main(){int n;float s,p,sum,all;while(~scanf("%d",&n)){sum=0;all=0;while(n--){scanf("%f%f",&s,&p);if(p!=-1) all+=s;if(p>=0&&p<=59) sum+=s*0;if(p>=60&&p<=69) sum+=s*1;if(p>=70&&p<=79) sum+=s*2;if(p>=80&&p<=89) sum+=s*3;if(p>=90) sum+=s*4;}if(all!=0)printf("%.2f\n",sum/all);elseprintf("-1\n");}return 0;}
The calculation of GPA
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 19126 Accepted Submission(s): 4417
Problem Description
每学期的期末,大家都会忙于计算自己的平均成绩,这个成绩对于评奖学金是直接有关的。国外大学都是计算GPA(grade point average) 又称GPR(grade point ratio),即成绩点数与学分的加权平均值来代表一个学生的成绩的。那么如何来计算GPA呢?
一般大学采用之计分法
A90 - 100 4 点
B80 - 89 3 点
C70 - 79 2 点
D60 - 69 1 点
E0 - 59 0 点
例如:某位学生修习三门课,其课目、学分及成绩分别为:
英文:三学分、92 分;化学:五学分、80 分;数学:二学分、60分,则GPA的算法如下:
科目 学分 分数 点数 分数×点数
英文 3 92 4 12
化学 5 80 3 15
数学 2 60 1 2
合计 10 29
29/10=2.9
2.9即为某生的GPA
下面有请你写一个用于计算GPA的程序。
一般大学采用之计分法
A90 - 100 4 点
B80 - 89 3 点
C70 - 79 2 点
D60 - 69 1 点
E0 - 59 0 点
例如:某位学生修习三门课,其课目、学分及成绩分别为:
英文:三学分、92 分;化学:五学分、80 分;数学:二学分、60分,则GPA的算法如下:
科目 学分 分数 点数 分数×点数
英文 3 92 4 12
化学 5 80 3 15
数学 2 60 1 2
合计 10 29
29/10=2.9
2.9即为某生的GPA
下面有请你写一个用于计算GPA的程序。
Input
包含多组数据,每组数据的第一行有一个数N,接下来N行每行表示一门成绩。每行有两个实型的数 s,p,s表示这门课的学分,p表示该学生的成绩(百分制)。如果p=-1则说明该学生这门课缺考,是不应该计算在内的。
Output
对每组数据输出一行,表示该学生的GPA,保留两位小数。如果GPA不存在,输出-1。
Sample Input
33 925 802 60
Sample Output
2.90
他说的实型数就是double型的数
#include<stdio.h>int main(){ int n,k; float s,p,sum,all; while(~scanf("%d",&n)) { sum=0; all=0; while(n--) { scanf("%f%f",&s,&p); if(p!=-1) all+=s; k=(int)p; if(k>=0&&k<=59) sum+=s*0; if(k>=60&&k<=69) sum+=s*1; if(k>=70&&k<=79) sum+=s*2; if(k>=80&&k<=89) sum+=s*3; if(k>=90) sum+=s*4; } if(all!=0&&sum!=0) printf("%.2f\n",sum/all); else printf("-1\n"); } return 0;}
第二种AC
#include<stdio.h>int main(){ int n,k; float s,p,sum,all; while(~scanf("%d",&n)) { sum=0; all=0; while(n--) { scanf("%f%f",&s,&p); if(p!=-1) { all+=s; k=(int)p; if(k>=90&&k<=100) sum+=s*4; else if(k>=80&&k<=89) sum+=s*3; else if(k>=70&&k<=79) sum+=s*2; else if(k>=60&&k<=69) sum+=s*1; } } if(all!=0||sum!=0) printf("%.2f\n",sum*1.0/all); else printf("-1\n"); } return 0;}
第三种方法:个人感觉最好。
#include<stdio.h>int main(){ int n,i; double s,p,m,sum; while(scanf("%d",&n)!=EOF) { m=sum=0.0; for(i=0;i<n;i++) { scanf("%lf%lf",&s,&p); if(p>=90.0&&p<=100.0) { m+=s; sum+=s*4.0; } else if(p>=80.0&&p<90.0) { m+=s; sum+=3.0*s; } else if(p>=70.0&&p<80.0) { m+=s; sum+=2.0*s; } else if(p>=60.0&&p<70.0) { m+=s; sum+=s; } else if(p>=0.0&&p<60.0) m+=s; } if(m!=0.0) printf("%.2lf\n",sum/m); else printf("-1\n"); } return 0;}
0 0
- HDU 1202 The calculation of GPA
- hdu 1202 The calculation of GPA
- HDU 1202 The calculation of GPA
- HDU 1202 The calculation of GPA
- HDU 1202 The calculation of GPA
- HDU 1202 The calculation of GPA
- hdu-1202-The calculation of GPA
- hdu 1202 The calculation of GPA
- HDU 1202 The calculation of GPA
- hdu 1202 The calculation of GPA
- hdu 1202 The calculation of GPA
- hdu 1202 The calculation of GPA
- hdu-1202 The calculation of GPA
- HDU 1202 The calculation of GPA
- HDU 1202 The calculation of GPA
- HDU 1202 The calculation of GPA
- The calculation of GPA HDU
- The calculation of GPA 1202
- JSP指令 include 和forward
- Android蓝牙开发
- 将代码转化成jQuery插件
- SDUT--Pots(二维BFS)
- eclipse 中安装插件三种方式
- HDU 1202 The calculation of GPA
- 数所库备份
- BFC
- 【JAVA】【SQL】一个demo(将文件中的数据取出来放到数据库中)
- IE10与Oracle EBS兼容性问题
- 7.JavaWeb基础 JaveBean
- poj 1163 The Triangle 线性动态规划
- UVa-113-Power of Cryptography
- [HTML] 实现三角形图标和圆形