HDU - 4802 GPA
来源:互联网 发布:怎么样网络投资 编辑:程序博客网 时间:2024/04/30 00:50
Description
In college, a student may take several courses. for each course i, he earns a certain credit (c i), and a mark ranging from A to F, which is comparable to a score (s i), according to the following conversion table
The GPA is the weighted average score of all courses one student may take, if we treat the credit as the weight. In other words,
An additional treatment is taken for special cases. Some courses are based on “Pass/Not pass” policy, where stude nts earn a mark “P” for “Pass” and a mark “N” for “Not pass”. Such courses are not supposed to be considered in computation. These special courses must be ignored for computing the correct GPA.
Specially, if a student’s credit in GPA computation is 0, his/her GPA will be “0.00”.
The GPA is the weighted average score of all courses one student may take, if we treat the credit as the weight. In other words,
An additional treatment is taken for special cases. Some courses are based on “Pass/Not pass” policy, where stude nts earn a mark “P” for “Pass” and a mark “N” for “Not pass”. Such courses are not supposed to be considered in computation. These special courses must be ignored for computing the correct GPA.
Specially, if a student’s credit in GPA computation is 0, his/her GPA will be “0.00”.
Input
There are several test cases, please process till EOF.
Each test case starts with a line containing one integer N (1 <= N <= 1000), the number of courses. Then follows N lines, each consisting the credit and the mark of one course. Credit is a positive integer and less than 10.
Each test case starts with a line containing one integer N (1 <= N <= 1000), the number of courses. Then follows N lines, each consisting the credit and the mark of one course. Credit is a positive integer and less than 10.
Output
For each test case, print the GPA (rounded to two decimal places) as the answer.
Sample Input
52 B3 D-2 P1 F3 A22 P2 N64 A3 A3 A4 A3 A3 A
Sample Output
2.330.004.00
#include <iostream>#include <cstdio>#include <cstring>#include <algorithm>#include <map>using namespace std;map<string, double> mp;int n;int main() {int m;string str;mp["A"] = 4.0, mp["A-"] = 3.7, mp["B+"] = 3.3;mp["B"] = 3.0, mp["B-"] = 2.7, mp["C+"] = 2.3;mp["C"] = 2.0, mp["C-"] = 1.7, mp["D"] = 1.3;mp["D-"] = 1.0, mp["F"] = 0.0;while (scanf("%d", &n) != EOF) {double ans = 0.00;int sum = 0;for (int i = 0; i < n; i++) {cin >> m >> str;if (str == "P" || str == "N")continue;sum += m;ans += (double) m * mp[str];}if (sum == 0)printf("0.00\n");else printf("%.2f\n", 1.0*ans/sum);}return 0;}
0 0
- HDU 4802 GPA
- hdu 4802 GPA(水题)
- HDU-#4802 GPA
- HDU - 4802 GPA
- HDU-4802-GPA
- hdu 4802 GPA
- hdu 4802 GPA
- GPA HDU 4802
- HDU 4802——GPA
- HDU——4802 GPA
- HDU 4802-GPA(水)
- hdu - 4802 - GPA(模拟)
- HDU 4802 GPA(水题)
- hdu 4802 GPA (map)
- HDU GPA
- HDU GPA
- [4802]:GPA
- hdu 2399 GPA
- 开博之日
- 第七章 7.5.5节练习 & 7.5.6节练习
- Android 来电拦截
- springmvc+jpa+springdata中遇到的错误解决办法
- 【C++】Byte/KB/MB/GB/TB/PB/EB 单位换算C++代码
- HDU - 4802 GPA
- SDUT 1125-New Game(DFS)
- Fuzzy C-mean 聚类原理及图像颜色分割的实例
- Android编译过程详解(一)
- android UncaughtExceptionHandler全局异常处理
- C#设计模式之适配器模式(Adapter Pattern)
- 使用单例模式需要注意的几个问题
- MySQL服务无法启动(2003 - Can't connect to MySQL server on‘localhost' (10038).)
- CSS3 文字边框 -webkit-text-stroke