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. 数据库迁移到Azure SQL Database用户无法登陆的问题

    业务情景:数据库是运维迁移上去的,好像使用了一个工具叫做Microsoft Data Migration Assistant,迁移之后,我的web应用无法连接数据库. 迁移之后的数据库内有User,但 ...

  2. 在OpenCV2.2后的版本中没有CvvImage类的解决方法(及出现错误:IntelliSense: 未定义标识符 "CvvImage" )

    首先在你的解决方案资源管理器中的头文件和源文件下分别添加 CvvImage.cpp 如下图: view类头上加个#include "CvvImage.h"  头文件,应该就可以解决 ...

  3. UVALive - 5031 Graph and Queries (并查集+平衡树/线段树)

    给定一个图,支持三种操作: 1.删除一条边 2.查询与x结点相连的第k大的结点 3.修改x结点的权值 解法:离线倒序操作,平衡树or线段树维护连通块中的所有结点信息,加个合并操作就行了. 感觉线段树要 ...

  4. HDU4416Good Article Good sentence(后缀自动机)

    Problem Description In middle school, teachers used to encourage us to pick up pretty sentences so t ...

  5. Swap Adjacent Elements

    You have an array a consisting of n integers. Each integer from 1 to n appears exactly once in this ...

  6. 类和对象(9)—— new和delete

    对象动态建立和释放 new 和delete 在软件开发过程中,常常需要动态地分配和撤销内存空间,例如对动态链表中结点的插入与删除.在C语言中是利用库函数malloc和free来分配和撤销内存空间的.C ...

  7. PADS Layout CAM 的中高级焊盘选项

    PADS Layout CAM 的中高级焊盘选项 PADS CAM Gerber 输出非常灵活. 以至于很多人跳坑. 以这个这选项,最好的方式就是不勾.

  8. BZOJ4130:[PA2011]Kangaroos

    浅谈\(K-D\ Tree\):https://www.cnblogs.com/AKMer/p/10387266.html 题目传送门:https://lydsy.com/JudgeOnline/pr ...

  9. 第9章 DOM对象,控制HTML元素

    学习地址:http://www.imooc.com/learn/10

  10. FPGA中竞争冒险问题的研究

    什么是竞争冒险? 1 引言     现场可编程门阵列(FPGA)在结构上由逻辑功能块排列为阵列,并由可编程的内部连线连接这些功能块,来实现一定的逻辑功能. FPGA可以替代其他PLD或者各种中小规模数 ...