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的权值不同 然后就是处理字典序的问题,当松弛 ...
随机推荐
- atom总结
window 系统 //查找 apm search emmet //安装 apm install emmet //删除 apm remove emmet
- idea下建立bootstrap项目
环境准备: 1.创建一个static web名为bootstrapDemo 2.在bootstrapDemo文件夹下安装bower npm install bower 会自动产生node-module ...
- Docker registry 与 持续集成
1.如何建立私有的 Docker Hub docker是一个非常好用的虚拟化工具. Registry 在git上分为老代码库和新代码库,老代码push,pull 存在性能问题,新代码库采用go语言编写 ...
- java-08多态与异常处理
1.运行以下代码: public class ParentChildTest { public static void main(String[] args) { Parent parent=new ...
- CODE FESTIVAL 2017 qual A--C - Palindromic Matrix(模拟所有情况,注意细节)
个人心得:其实本来这题是有规律的不过当时已经将整个模拟过程都构思出来了,就打算试试,将每个字符和总和用优先队列 装起来,然后枚举每个点,同时进行位置标志,此时需要多少个点的时候拿出最大的和出来,若不满 ...
- [转]移动端HTML5<video>视频播放优化实践
遇到的挑战 移动端HTML5使用原生<video>标签播放视频,要做到两个基本原则,速度快和体验佳,先来分析一下这两个问题. 下载速度 以一个8s短视频为例,wifi环境下提供的高清视频达 ...
- c++11之一: 基于范围的for循环
#include <iostream> using namespace std; int main(){ ]{,,,,}; for (int& e: ary) e *= ; for ...
- PHP Warning: Module 'modulename' already loaded in Unknown on line 0 的解决方法
今天无间断服务加载php-fpm时,爆出了一个错误:PHP Warning: Module 'xhprof' already loaded in Unknown on line 0 <br / ...
- maven打包指定main函数的入口,生成依赖的包
为了使Jar包中指定Main方法位置和生成依赖包,需要在pom文件中加入如下配置: <build> <plugins> <plugin> <groupId&g ...
- Python 正则表达式取值
import re class Retest: def __init__(self,string,path): self.string = string self.path = path def re ...