1. 程式人生 > >一題簡單英文題~

一題簡單英文題~

//很好奇AC率為啥這麼低
1269: GPA
Time Limit: 1 Sec Memory Limit: 128 MB
Submit: 1064 Solved: 320
[Submit][Status][Web Board]
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

A B C D F

4.0 3.0 2.0 1.3 0

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 students earns 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<100), the number of courses. Then follow N lines, each consists 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

4
2 B
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

3.00
0.00
4.00

HINT

For the first test case:

P/N is not considered.

Source

FDU
ACcode~:

#include <stdio.h>
typedef struct gpa
{
    double c;
    char s;
}GPA;
int main()
{
    int n;
    while(~scanf("%d",&n))
    {
        GPA date[n];
        double sum = 0,num = 0,aver = 0;
        for(int i = 0; i < n; i++)
        {
            scanf("%lf %c",&date[i].c,&date[i].s);
            switch(date[i].s)
            {
                case 'A':sum += date[i].c*4.0;num += date[i].c;break;
                case 'B':sum += date[i].c*3.0;num += date[i].c;break;
                case 'C':sum += date[i].c*2.0;num += date[i].c;break;
                case 'D':sum += date[i].c*1.3;num += date[i].c;break;
                case 'F':num += date[i].c;break;
            }
        }
        if(sum)
          aver = sum / num;
        printf("%.2lf\n",aver);
    }
    return 0;
}