HDU 1202 The calculation of GPA
来源:互联网 发布:linux oracle服务重启 编辑:程序博客网 时间:2024/05/16 18:42
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的程序。
Input
包含多组数据,每组数据的第一行有一个数N,接下来N行每行表示一门成绩。每行有两个实型的数 s,p,s表示这门课的学分,p表示该学生的成绩(百分制)。如果p=-1则说明该学生这门课缺考,是不应该计算在内的。
Output
对每组数据输出一行,表示该学生的GPA,保留两位小数。如果GPA不存在,输出-1。
Sample Input
3
3 92
5 80
2 60
Sample Output
2.90
C++
#include<iostream>#include<cstdio>struct cj //用来存储学分,分数和点数*学分{ double a,b; int c;};using namespace std;int main(){ struct cj a[1000]; int b,c,d,e,f; double m,n; while(cin>>b) { m=0;n=0; //m存所有点数*学分,n存所有学分 for(c=0;c<b;c++) { scanf("%lf %lf",&a[c].b,&a[c].a); } for(c=0;c<b;c++) //用来确定点数 { if(a[c].a>=90) a[c].c=4; else if(a[c].a>=80) a[c].c=3; else if(a[c].a>=70) a[c].c=2; else if(a[c].a>=60) a[c].c=1; else a[c].c=0; if(a[c].a!=-1) { m=m+a[c].b*a[c].c; n=a[c].b+n; } } if(m!=0) { m=m/n; printf("%.2lf\n",m); } else cout<<"-1"<<endl; } 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
- Node.js http.request()返回响应出现乱码的解决方案
- 数据库优化——备份与恢复
- org.json.JSONException: No value for
- 将字符串转换为float类型
- Base64(四)
- HDU 1202 The calculation of GPA
- HDU1532(最大流EK算法模板题)
- LeetCode:553. Optimal Division
- HTML5 WebStorage
- 运算符/注释
- Proxy——代理模式
- JDK-jre
- EA&UML日拱一卒--序列图(Sequence Diagram)::并行和临界区
- python小脚本 自动清理大于七天的Tomcat日志