Problem Description
In college, a student may take several courses. for each course i, he earns a certain credit (ci), and a mark ranging from A to F, which is comparable to a score (si), 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”.
 
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.
 
Output
For each test case, print the GPA (rounded to two decimal places) as the answer.
 
Sample Input
5
2 B
3 D-
2 P
1 F
3 A
2
2 P
2 N
6
4 A
3 A
3 A
4 A
3 A
3 A
 
Sample Output
2.33 0.00 4.00

思路:输入数据后进行判断,如果是标准的GPA,则返回相应的数据,并用一个全局变量来表示是否全部都是非法的GPA,如果是则直接输出0即可

 #include <iostream>
#include <string>
using namespace std;
int flag=;//全局变量,用来标识是否全是P或者N
float table(char *p)
{
//flag=0;
if(p[]=='P'||p[]=='N')
return 0.0;
else
{
if(p[]=='A'&&p[]!='-')
{flag++;return 4.0;}
else if(p[]=='A'&&p[]=='-')
{flag++;return 3.7;}
else if(p[]=='B'&&p[]=='+')
{flag++;return 3.3;}
else if(p[]=='B'&&p[]!='-'&&p[]!='+')
{flag++;return 3.0;}
else if(p[]=='B'&&p[]=='-')
{flag++;return 2.7;}
else if(p[]=='C'&&p[]=='+')
{flag++;return 2.3;}
else if(p[]=='C'&&p[]!='-'&&p[]!='+')
{flag++;return 2.0;}
else if(p[]=='C'&&p[]=='-')
{flag++;return 1.7;}
else if(p[]=='D'&&p[]!='-')
{flag++;return 1.3;}
else if(p[]=='D'&&p[]=='-')
{flag++;return 1.0;}
else {flag++;return 0.0;}
}
}
int main()
{
int n=;
int i=;
float GPA=0.0;
int c;
int ci=;
char s[]={};
while(scanf("%d",&n)!=EOF)
{
GPA=0.0;
ci=0.0;
flag=;
for(i=;i<n;i++)
{
cin>>c>>s;
GPA+=((float)c)*table(s);
if(!(s[]=='P'||s[]=='N'))
ci+=c;
}
if(flag==)
printf("0.00\n");
else
{
GPA=GPA/(float)ci;
printf("%.2f\n",GPA);
}
}
}

HDOJ 4802 GPA的更多相关文章

  1. hdu 4802 GPA 水题

    GPA Time Limit: 20 Sec  Memory Limit: 256 MB 题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=4802 Des ...

  2. HDU - 4802 - GPA (水题)

    题意: 计算GPA,输入一个数字和一个字符串,用 数字×字符串对应的数值 思路: 用map对应数值,要注意的是字符串为P或者N的时候,不计入结果 代码: #include<iostream> ...

  3. HDOJ 1202 The calculation of GPA

    Problem Description 每学期的期末,大家都会忙于计算自己的平均成绩,这个成绩对于评奖学金是直接有关的.国外大学都是计算GPA(grade point average) 又称GPR(g ...

  4. HDOJ 1009. Fat Mouse' Trade 贪心 结构体排序

    FatMouse' Trade Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) ...

  5. HDOJ 2317. Nasty Hacks 模拟水题

    Nasty Hacks Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Tota ...

  6. HDOJ 1326. Box of Bricks 纯水题

    Box of Bricks Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) To ...

  7. HDOJ 1004 Let the Balloon Rise

    Problem Description Contest time again! How excited it is to see balloons floating around. But to te ...

  8. 16090202(剑灵GPA)

    [目标] 剑灵GPA [思路] 1 2 绘制角色DrawCall body 5526面片 2.1[第一个DrawCall]63 RT 这个DrawCall PS VS 参数列表 VS // // Ge ...

  9. hdoj 1385Minimum Transport Cost

    卧槽....最近刷的cf上有最短路,本来想拿这题复习一下.... 题意就是在输出最短路的情况下,经过每个节点会增加税收,另外要字典序输出,注意a到b和b到a的权值不同 然后就是处理字典序的问题,当松弛 ...

随机推荐

  1. Kali 2.0 安装后的初始配置

    准备 1.VMware Workstation 2.kali-linux-2.0-amd64.iso 安装 手动安装 VMware 创建新的虚拟机,先不导入ISO文件,系统选择Debian 7.x 6 ...

  2. IT从业人员必看的10个论坛(转)

    IT方面的论坛太多了,有综合,有专业,有行业,在各个论坛里混了几年,体会颇深,以前是论坛哪里人多,往哪里去,新浪论坛,网易是经常去的,人多啊,好几十万,去了以后才发现没有意思,没有共同的语言,于是逛专 ...

  3. docker 存储

    [root@docker01 ~]# docker run --name b1 -v /data -it busybox / # ls bin data dev etc home proc root ...

  4. [ Laravel 5.5 文档 ] 数据库操作 —— 在 Laravel 中轻松实现分页功能

     简介 在其他框架中,分页是件非常痛苦的事,Laravel 让这件事变得简单易于上手.Laravel 的分页器与查询构建器和 Eloquent ORM 集成在一起,并开箱提供方便的.易于使用的.基于 ...

  5. mysql之 double write 浅析

    http://blog.itpub.net/22664653/viewspace-1140915/ 介绍double write之前我们有必要了解partial page write 问题 :     ...

  6. Python collections系列之有序字典

    有序字典(orderedDict ) orderdDict是对字典类型的补充,他记住了字典元素添加的顺序 1.创建一个有序字典 import collections dic = collections ...

  7. 第七篇 PHP编码规范

    当码农多年,始终进步不大,前面说了第一个原因是没有明确的目标:第二个原因是没有养成良好的习惯(即优秀的职业规范). 1)pear 规范 http://pear.php.net/manual/en/st ...

  8. boost_1.61.0编译安装

    1.下载源码boost_1_61_0.zip 2.进入目录 C:\Program Files (x86)\Microsoft Visual Studio 12.0\Common7\Tools\Shor ...

  9. python3小例子:scrapy+mysql

    https://blog.csdn.net/u010151698/article/details/79371234

  10. Chroma Oracle 安装宝典,吐血整理

    尼玛,太坑爹!安装: 1.Chroma Application Service 2. PL SQL 安装Oracle 11g 的步骤和过程: 第一步:只能安装 Oracle 11g 64 bit 数据 ...