HDOJ 4802 GPA

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”.
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.
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
思路:输入数据后进行判断,如果是标准的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的更多相关文章
- hdu 4802 GPA 水题
GPA Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=4802 Des ...
- HDU - 4802 - GPA (水题)
题意: 计算GPA,输入一个数字和一个字符串,用 数字×字符串对应的数值 思路: 用map对应数值,要注意的是字符串为P或者N的时候,不计入结果 代码: #include<iostream> ...
- HDOJ 1202 The calculation of GPA
Problem Description 每学期的期末,大家都会忙于计算自己的平均成绩,这个成绩对于评奖学金是直接有关的.国外大学都是计算GPA(grade point average) 又称GPR(g ...
- HDOJ 1009. Fat Mouse' Trade 贪心 结构体排序
FatMouse' Trade Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) ...
- HDOJ 2317. Nasty Hacks 模拟水题
Nasty Hacks Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Tota ...
- HDOJ 1326. Box of Bricks 纯水题
Box of Bricks Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) To ...
- HDOJ 1004 Let the Balloon Rise
Problem Description Contest time again! How excited it is to see balloons floating around. But to te ...
- 16090202(剑灵GPA)
[目标] 剑灵GPA [思路] 1 2 绘制角色DrawCall body 5526面片 2.1[第一个DrawCall]63 RT 这个DrawCall PS VS 参数列表 VS // // Ge ...
- hdoj 1385Minimum Transport Cost
卧槽....最近刷的cf上有最短路,本来想拿这题复习一下.... 题意就是在输出最短路的情况下,经过每个节点会增加税收,另外要字典序输出,注意a到b和b到a的权值不同 然后就是处理字典序的问题,当松弛 ...
随机推荐
- 在.Net下使用redis基于StackExchange.Redis--登录功能
研究了下redis在.net下的使用,因为以前在java上用redis用的是jedis操作,在.net不是很熟悉,在网站上也看了一部分的.net下redis的使用,大部分都是ServiceStack. ...
- BEC translation exercise 2
Forest fires are a regular feature of Chile's hot, arid summers.智利夏天炙热.干燥,常发生森林火灾.A nearly decade-lo ...
- 1.Linux和Unix区别
整理来源于网络:http://blog.csdn.net/xiaojianpitt/article/details/6377419 有很多初学Linux的人比较关心Linux和windows的区别,这 ...
- loj #6247. 九个太阳
求 $\sum\limits_{i=1}^n [k | i] \times C_n^i$ 膜 $998244353$ $n \leq 10^{15},k \leq 2^{20}$ $k$ 是 $2$ ...
- Linux下anaconda的安装
http://peteryuan.net/use-anaconda/ http://www.jianshu.com/p/03d757283339
- Spark入门实战系列
转自:http://www.cnblogs.com/shishanyuan/p/4699644.html 这一两年Spark技术很火,自己也凑热闹,反复的试验.研究,有痛苦万分也有欣喜若狂,抽空把这些 ...
- Python函数-enumerate()
enumerate(sequence, [start=0]) 作用: 将可循环序列sequence以start开始分别列出序列数据和数据下标,即对一个可遍历的数据对象(如列表.元组或字符串),enum ...
- mysql之 MySQL 主从基于position复制原理概述
1 .主从复制简介MySQL 主从复制就是将一个 MySQL 实例(Master)中的数据实时复制到另一个 MySQL 实例(slave)中,而且这个复制是一个异步复制的过程.实现整个复制操作主要由三 ...
- bzoj 4503 两个串——FFT
题目:https://www.lydsy.com/JudgeOnline/problem.php?id=4503 翻转T,就变成卷积.要想想怎么判断. 因为卷积是乘积求和,又想到相等的话相减为0,所以 ...
- 首次db查询时延迟明显高于后面几次。
1.如果排查到时db相关的问题的话,一般都是连接池的配置问题. 在配置好连接池时一定要注意对连接也进行初始化配置,否则可能出现连接池初始化了,但是连接并没有初始化,这样在第一次查询的时候可能会出现较大 ...