GPA


Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 814    Accepted Submission(s): 530


Problem 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



HDU4802-GPA_sed


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,



HDU4802-GPA_#include_02


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


Hint


 



Source


​2013ACM/ICPC亚洲区南京站现场赛——题目重现 ​


 


 

 

//注意浮点数和0的比较还有字符串的处理就OK了

AC代码:

#include<stdio.h>
#include<string.h>
char score[5];
double Fun(char score[])
{
double x;
if(score[0]>'D'&&score[0]!='F')
return -1.0;
else
{
if(strlen(score)==1)
{
switch(score[0])
{
case 'A':x=4.0;break;
case 'B':x=3.0;break;
case 'C':x=2.0;break;
case 'D':x=1.3;break;
case 'F':x=0;break;
}
}
else
{
switch(score[0])
{
case 'A':x=3.7;break;
case 'B':{
switch(score[1])
{
case '+':x=3.3;break;
case '-':x=2.7;break;
}
}break;
case 'C':{
switch(score[1])
{
case '+':x=2.3;break;
case '-':x=1.7;break;
}
}break;
case 'D':x=1.0;break;
}
}
return x;
}
}
int main()
{
int i,n;
double sum1,sum2,m;
while(scanf("%d",&n)!=EOF)
{
sum1=0;sum2=0;
for(i=0;i<n;i++)
{
memset(score,0,sizeof(score));
scanf("%lf %s",&m,score);
if(Fun(score)>-1.0)
{
sum1+=(m*Fun(score));
sum2+=m;
}
}
if(!(sum2>-0.000001&&sum2< 0.000001) )
printf("%.2lf\n",sum1/sum2);
else
printf("0.00\n");
}
return 0;
}