hdu 1202 The calculation of GPA
来源:互联网 发布:比较好用的浴帽知乎 编辑:程序博客网 时间:2024/05/19 00:53
The calculation of GPA
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 19740 Accepted Submission(s): 4544
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题目大意:求学生的GPA,学分成以计分数,再除以分数的总和思路:先用一个函数求出分数对应的学分,用for循环,每次输入,如果分数不是-1就用sum加上分数所对应的学分和计分的成积再除以学分的总和, 如果sum等于0;则证明没有学分,就没有GPA,输出-1;还有不管有几门课缺考都要除以学分的总和。这题真是坑啊,题上明明写的80到89,实际上89.9也算3计分的!开始的时候写的<=89,然后错了一下午,应该是<90,唉,居然是实型输入2014,10,31#include<stdio.h>int f(double m){int k;if(m>=90&&m<=100) k=4;else if(m>=80&&m<90) k=3;else if(m>=70&&m<80) k=2;else if(m>=60&&m<70) k=1;else if(m>=0&&m<60) k=0;return k;}int main(){int n,i;double sum,x,y,z,j;while(scanf("%d",&n)!=EOF){sum=j=0.0; for(i=0;i<n;i++){scanf("%lf%lf",&x,&y);j+=x;//分数的总和 if(y!=-1){z=f(y);sum+=x*z;}}if(sum==0) printf("-1\n");elseprintf("%.2lf\n",sum/j);}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
- iOS键盘总结
- 如何在的ServiceManager在ZF2注册一个Zend \ Log实例
- springside4-master访问/task报500错误
- freemarker 将String 按照指定字符分割并生成 list 循环
- 一点心得体会
- hdu 1202 The calculation of GPA
- 【bnu 4353 删格游戏】(博弈)
- poj 1160 Post Office(DP)
- linux中断--中断原理分析
- 小黑小波比.Ubuntu下hoststool安装与使用为上谷歌安卓官网
- 实现蝴蝶翩翩飞舞的效果
- Notepad++不打开最近打开的文件
- 《私房菜》3rd 笔记0. 目录
- Best Time to Buy and Sell Stock